main should return int.
You have while(r>0) and r is uninitialized.
10931 - Parity
Moderator: Board moderators
-
- Guru
- Posts: 5947
- Joined: Thu Sep 01, 2011 9:09 am
- Location: San Jose, CA, USA
Re: 10931 i can't understand why WA!!!
Check input and AC output for thousands of problems on uDebug!
-
- New poster
- Posts: 36
- Joined: Sun Mar 18, 2012 8:18 am
Re: 10931 i can't understand why WA!!!

Last edited by cse.mehedi on Sat Jul 07, 2012 4:32 pm, edited 1 time in total.
Re: 10931 - Parity (why compile error)
#include<cstdio>
#include<cstdlib>
#include<cstring>
int main()
{
long long int k,i,j,d,c,n;
char a[1000000];
while(scanf("%lld",&n)==1&&n!=0)
{
c=0;
j=0;
while(n!=0)
{
d=n%2;
a[j]=d+48;
n=n/2;
j++;
}
for(i=0;a!=NULL;i++)
{
if(a=='1')
{
c++;
}
}
strrev(a);
printf("The parity of %s is %lld (mod 2).\n",a,c);
memset(a,0,sizeof a);
}
return 0;
}
#include<cstdlib>
#include<cstring>
int main()
{
long long int k,i,j,d,c,n;
char a[1000000];
while(scanf("%lld",&n)==1&&n!=0)
{
c=0;
j=0;
while(n!=0)
{
d=n%2;
a[j]=d+48;
n=n/2;
j++;
}
for(i=0;a!=NULL;i++)
{
if(a=='1')
{
c++;
}
}
strrev(a);
printf("The parity of %s is %lld (mod 2).\n",a,c);
memset(a,0,sizeof a);
}
return 0;
}
-
- Guru
- Posts: 5947
- Joined: Thu Sep 01, 2011 9:09 am
- Location: San Jose, CA, USA
Re: 10931 - Parity
Check My Submissions and you can see the reason for your compile error.
Check input and AC output for thousands of problems on uDebug!