got acc after a long time,
input processing was wrong actually.
10176 - Ocean Deep ! - Make it shallow !!
Moderator: Board moderators
-
- Learning poster
- Posts: 74
- Joined: Fri May 08, 2009 5:16 pm
Re: 10176 - Ocean Deep! Make it shallow!!
Why this code generate WA ,could anybody give some test cases?
Code: Select all
#include<cstdio>
#include<string>
#include<iostream>
#define mod 131071
using namespace std;
void doit(string s){
int sol=0;
for(int i=0;i<s.length();i++){
sol*=2;
sol%=mod;
sol=(sol+(int)(s[i]-'0'))%mod;
}
sol%=mod;
if(sol==0)puts("YES");
else puts("N0");
}
int main(){
string s,cad="";
while(cin>>s){
if(s[s.length()-1]=='#'){
doit(cad+s.substr(0,s.length()-1));
cad="";
}
else cad+=s;
}
}
Re: 10176 - Ocean Deep! Make it shallow!!
I found my mistake !!
Re: 10176 - Ocean Deep! Make it shallow!!
i am getting WA ,,, but failed to find out what is the wrong!!
#include<stdio.h>
#include<string.h>
#include<string>
#include<algorithm>
#include<iostream>
using namespace std;
int main()
{
char str[20000],temp[20000];
int i,j=0;
while(scanf("%c",&str[0])==1)
{
j=0;
int p=0;
if(str[0]!=' '&&str[0]!='\n'){
temp[j]=str[0];
j++;
}
for(i=1;i>=0;i++)
{
scanf("%c",&str);
if(str=='#'){
temp[j]='\0';
break;
}
if(str!=' '&&str!='\n'){
temp[j]=str;
j++;
}
}
int l=strlen(temp);
for(i=0;i<l;i++)
{
int k=(temp-48)+p*2;
p=k%131071;
}
if(p==0)
printf("YES\n");
else
printf("NO\n");
}
return 0;
}
plz help
#include<stdio.h>
#include<string.h>
#include<string>
#include<algorithm>
#include<iostream>
using namespace std;
int main()
{
char str[20000],temp[20000];
int i,j=0;
while(scanf("%c",&str[0])==1)
{
j=0;
int p=0;
if(str[0]!=' '&&str[0]!='\n'){
temp[j]=str[0];
j++;
}
for(i=1;i>=0;i++)
{
scanf("%c",&str);
if(str=='#'){
temp[j]='\0';
break;
}
if(str!=' '&&str!='\n'){
temp[j]=str;
j++;
}
}
int l=strlen(temp);
for(i=0;i<l;i++)
{
int k=(temp-48)+p*2;
p=k%131071;
}
if(p==0)
printf("YES\n");
else
printf("NO\n");
}
return 0;
}
plz help
Many of life’s failures are people who did not realize how close they were to success when they gave up.
-
- Guru
- Posts: 5947
- Joined: Thu Sep 01, 2011 9:09 am
- Location: San Jose, CA, USA
Re: 10176 - Ocean Deep! Make it shallow!!
It looks like you figured it out
Check input and AC output for thousands of problems on uDebug!
-
- Experienced poster
- Posts: 148
- Joined: Sun Jul 13, 2014 4:32 am
- Location: Rangpur, Bangladesh
Re: 10176 - Ocean Deep ! - Make it shallow !!
Got Accepted
Last edited by Shahidul.CSE on Tue Nov 18, 2014 7:53 am, edited 1 time in total.
Md. Shahidul Islam
Dept. of CSE at Begum Rokeya University, Rangpur, Bangladesh
UVa id: http://uhunt.felix-halim.net/id/438420
My facebook account,
Email me: shahidul.cse.brur@gmail.com
Dept. of CSE at Begum Rokeya University, Rangpur, Bangladesh
UVa id: http://uhunt.felix-halim.net/id/438420
My facebook account,
Email me: shahidul.cse.brur@gmail.com
-
- Guru
- Posts: 5947
- Joined: Thu Sep 01, 2011 9:09 am
- Location: San Jose, CA, USA
Re: 10176 - Ocean Deep ! - Make it shallow !!
At each step as you convert the binary string to a decimal value do a modulus 131071.
Check input and AC output for thousands of problems on uDebug!