Page 1 of 2
10469 - To Carry or not to Carry
Posted: Thu Apr 24, 2003 6:24 am
by BestIvan
Problem 10469 is quite simple, but how would judge input the test number?
should i keep on reading until it terminate my problem anyway?
it hasn't been announced as a "multiple input"
Posted: Thu Apr 24, 2003 9:34 am
by kmhasan
The problem statement clearly states,
Input ends at EOF.
If you're writing the solution in C, you could use:
[c]
int main() {
while (scanf("%d %d",&a,&b)==2) {
/* do whatever is needed */
}
return 0;
}
[/c]
Thanks
Posted: Thu Apr 24, 2003 12:50 pm
by BestIvan
It's alright, thank you very much
Actually i've just tried to use C++ and stream I/O instead of C
so i was not sure how to deal with EOF then

Posted: Thu Apr 24, 2003 6:46 pm
by Adil
for C++ and stream I/O, i think you can use:
[cpp]while(cin >> a >> b)
{
...
}[/cpp]
hiiiiiiiii
Posted: Fri Oct 10, 2003 10:38 pm
by nikhil
just print...
(a^b)
get accccccccccccccc
thx.
Re: hiiiiiiiii
Posted: Wed Jun 06, 2007 5:50 am
by Deny Sutani
nikhil wrote:just print...
(a^b)
get accccccccccccccc
thx.
OMG, I wasted my time to convert a and b to binary number and XoR them. With my previous code, I got WA. But with only one line code, I got AC. Thank u very much.
I keep getting wrong answer
Posted: Tue Jul 10, 2007 8:59 pm
by mario
My code is in C++, is really simple. It works well in my computer but maybe I should input some critical inputs. I just keep getting WA and I have no idea why.
Here is my code:
/*
problem# 10469
*/
#include <iostream>
....
.....deleted
.....
.....
int main ()
{
while( !cin.eof() )
{
.....
.....
..deleted...
................
cout << result << endl;
}
return 0;
}
Thanks
Posted: Wed Jul 11, 2007 10:36 am
by mmonish
>>mario
I generate some random test case & compare ur output with my AC code output. ur code generate one extra output.Problem in ur input terminating condition.
instead of using this u can use
Hope this helps.
Posted: Thu Jul 12, 2007 3:27 pm
by mario
Thanks, that was all. I got AC when I changed to cin >> x >> y.
Posted: Thu Jul 12, 2007 3:46 pm
by helloneo
If you got AC, remove your code plz..

Re: 10469 - To Carry or not to Carry
Posted: Sat May 17, 2008 11:35 am
by Tarif
I'm having WA for this problem but don't know why. My answers seem to be alright. I've used a^b for output and
while(scanf("%d %d", &a, &b);
what should i do?

Re: 10469 - To Carry or not to Carry
Posted: Sat May 17, 2008 5:47 pm
by andmej
Make sure you use unsigned integers. Which also means you need to use "%u" instead of "%d" in both scanf and printf.
Edit: Fixed mistake.
Re: 10469 - To Carry or not to Carry
Posted: Fri Oct 24, 2008 9:02 pm
by aliahmed
I got runtime error with this code. re is common for me. I'm newbie. can someone help me to find the mistake in my code.
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<stdlib.h>
int main()
{
long long f,f1,f2,j,i,n,b,l1,l2,l,sum,mul,k,l3;
char str[100],str1[100],res[100],h[100],ch,ch1;
while(1)
{
sum=0;
for(j=0; j<2; j++)
{
if(scanf("%lld",&n)==EOF)
exit(1);
for(i=0; ; i++)
{
if(n==0)
{
str='0';
str[i+1]='\0';
break;
}
if(n==1)
{
str='1';
str[i+1]='\0';
break;
}
if(n%2==0)
str='0';
else
{
str='1';
}
n=n/2;
}
if(j==0)
{
strcpy(str1,str);
str[0]='\0';
}
}
l1=strlen(str);
l2=strlen(str1);
if(l1>l2)
b=l1;
else
b=l2;
f=1;
f1=1;
f2=0;
k=0;
for(i=0; i<b; i++)
{
ch=str-48;
ch1=str1-48;
if(ch<0 || ch>1 || f==0)
{
ch=0;
f=0;
}
else if(ch1<0 || ch1>1 || f1==0)
{
ch1=0;
f1=0;
}
res[k++]=ch^ch1+48;
}
res[k]='\0';
l3=strlen(res);
k=0;
for(i=0; ; i++)
{
l3--;
if(res=='\0')
break;
if(res[l3]=='0' && f2==0)
continue;
f2=1;
h[k++]=res[l3];
}
h[k]='\0';
l=strlen(h)-1;
for(i=0; ;i++)
{
if(h=='\0')
break;
mul=(h[l--]-48)*pow(2,i);
sum+=mul;
}
str[0]='\0';
str1[0]='\0';
h[0]='\0';
res[0]='\0';
printf("%lld\n",sum);
}
return 0;
}
Re: 10469 - To Carry or not to Carry
Posted: Fri Oct 24, 2008 10:35 pm
by andmej
You are over complicating the problem.
Study the bitwise XOR operator.
10469 - To Carry or not to Carry
Posted: Tue Mar 05, 2013 5:27 am
by omarking05
please can anyone tell me whats wrong with this code ?
Code: Select all
#include <iostream>
#include <string>
#include <sstream>
using namespace std;
string convert (unsigned long long int n)
{
string s;
stringstream out;
out << n;
s = out.str();
return s;
}
int bit (unsigned long long int n)
{
unsigned long long int rem=0,sum=0,i=1;
while (n>0)
{
rem=n%2;
sum+=(i*rem);
n/=2;
i=i*10;
}
return sum;
}
int b_d(string w)
{
unsigned long long int result = 0, pow = 1;
for ( int i = w.length() - 1; i >= 0; --i, pow <<= 1 ) //pow=pow<<1; shifting pow to the left
result += (w[i] - '0') * pow;
return result;
}
int main()
{
string w1,w2,k,w3,w4;
unsigned long long int n1,n2,l1,l2,l3;
while(cin>>n1>>n2)
{
w1=w2=w3=w4=k="";
l1=l2=0;
n1=bit(n1);
n2=bit(n2);
cout<<n1<<" "<<n2<<endl;
w1=convert(n1);
w2=convert(n2);
l1=w1.length();
l2=w2.length();
if (l2>l1)
for (int i=l1;i<l2;i++)
w3+="0";
else
for (int i=l2;i<l1;i++)
w4+="0";
w3+=w1;
w4+=w2;
for (int i=0;i<w3.length();i++)
{
if ( (w3[i]=='1' && w4[i]=='0') || (w3[i]=='0' && w4[i]=='1') )
k+="1";
else k+="0";
}
cout<<w3<<" "<<w4<<" "<<k<<endl;
cout<<b_d(k)<<endl;
}
return 0;
}
thanks in advance .