Page 3 of 12

Posted: Tue Dec 24, 2002 5:55 pm
by incin
This gives WA, but it works for me,
btw, ive never heard of 'long long',
it isnt avaliable to me

[cpp]
int main() {
double a,b;
while (cin >> a) {
cin >> b;
if (a>b) printf("%.0f\n",a-b);
else printf("%.0f\n",b-a);
}
return 0;
}[/cpp]

LONG LONG

Posted: Tue Dec 24, 2002 6:11 pm
by Ming Han
Hi there,

If you want to get correct answer, you have to use Long Long.
You cannot use double.

What compiler are you using?

Posted: Wed Dec 25, 2002 4:02 am
by incin
i use visual c++ 7, it doesn't support the long long. I think that the double is working for me because doubles are 64 bit in 'microsoft'. Do you have a way for me to use the long long?

Posted: Wed Dec 25, 2002 7:30 am
by ec3_limz
I think that in MSVC, long data type is also 64-bit. This is not true for the GNU C++ compiler.

BTW, I have a big problem when using C standard IO functions to print out the values of long long int variables.

For example.

[cpp]#include <stdio.h>
int main() {
printf("%lld\n", 2147483648LL); // 2147483648 overflows int
return 0;
}[/cpp]

Output: -2147483648

I have this problem when compiling with MinGW compiler and Cygwin compiler.

Can anyone tell me how my problem can be resolved without using standard C++ I/O streams? Thank you.

Long Long

Posted: Wed Dec 25, 2002 8:19 am
by Ming Han
To incin:

You mean that is no way to use Long Long?

[cpp]long long i;[/cpp]

BTW, I suggest you use Dev C++. It uses the Mingw/GCC 3.2 Compiler.
http://www.bloodshed.net/dev/devcpp.html

And did you get Accepted using Double?

-------------------------------------------------------------
To: Lim Zhuomin

Maybe the solution is to use cout??
BTW, you are using cygwin g++ compiler?
To my knowledge, cygwin eats up lots of resources on windows.

Ming Han

You CAN use double for this problem

Posted: Wed Dec 25, 2002 9:53 am
by Whinii F.
1. Simply try using %.0lf instead of %.0f, then you'll get Accepted.
2. In Visual C++, you can use __int64. And, I believe that GCC's printf and scanfs don't support long long int.. (Read that from a problem statement in this site)

add by edit:
Yes, I found it.. It was problem 10392. http://acm.uva.es/p/v103/10392.html

I wonder if it is trustable..

WA

Posted: Thu Jan 23, 2003 3:22 pm
by thechaoshacker
I read all the threads on this problem. I still can't figure out why I am getting WA. Could u please help me out ?
Here is my code.

#include<iostream.h>

int main()
{
unsigned long long int a,b,tempa,tempb;
while(!cin.eof())
{
cin>>a>>b;
if(a > b)
tempa=a-b;
else
tempa=b-a;
cout<<tempa;
}
return 0;
}
TheChaosHacker

ACM 10055

Posted: Thu Jan 23, 2003 5:47 pm
by Ming Han
Maybe you should try the 2 tips below:

[cpp]
while(cin>>a>>b)
[/cpp]

AND

[cpp]
cout<<tempa<<endl;
[/cpp]

IF you have extra difficulties, please visit my website.

Accepted

Posted: Sun Jan 26, 2003 1:46 pm
by thechaoshacker
Thanx !
I changed those two lines and it worked. What was going wrong ?
TheChaosHacker

Tips

Posted: Sun Jan 26, 2003 1:49 pm
by Ming Han
You forgot to go to the next line after each output.
(cout<<tempa<<endl;)

Posted: Sat Mar 15, 2003 9:59 am
by Red Scorpion
Try to use long long integer instead of using integer

Code: Select all

While (scanf ("%lld %lld", &a, &b) == 2) {

}

10055(W.A)

Posted: Sat Mar 15, 2003 10:03 am
by lendlice
I get W.A
Anyone can help me
[cpp]#include<stdio.h>
#include<string.h>
main()
{
char in1[100000],in2[100000];
int n1=0,n2=0,ans[100000],i=0,i1=0,count=0,tr=0,carry=0;
scanf("%s%s",in1,in2);
n1=strlen(in1);
n2=strlen(in2);
count=n2;
i1=n2;
n2--;
n1--;
for(count=count-1;count>=0;count--)
{
if(n1>=0)
ans[count]=in2[n2]-in1[n1]-carry;
else
ans[count]=in2[n2]-carry-'0';
carry=0;
if(ans[count]<0)
{
carry=1;
ans[count]=10+ans[count];
}
n1--;
n2--;
}
for(i=0;i<i1;i++)
{
if(ans==0||ans==48)
{
if(tr!=0)
{
printf("%d",ans);
tr++;
}
}
else
{
printf("%d",ans);
tr++;
}
}
printf("\n");
tr=0;
}[/cpp]

Posted: Sat Mar 15, 2003 11:50 am
by Hisoka
I think for this problem the result is |in2-in1| and you must use long long or double.

Posted: Sun Mar 16, 2003 4:22 am
by lendlice
I use array
So I not to need use long or double.

Posted: Sun Mar 16, 2003 5:30 pm
by Hisoka
OK, if you want to use array for this problem, you have great risk. I said to you before, for this problem the result is |in2-in1|, your program cannot solve this:

Code: Select all

100 200
200 100
555 555
your output:

Code: Select all

100
900
blank line
your second and last output are wrong! true output for they are 100 and 0, and for your input must be:
while(scanf("%s %s",in1,in2)==2){
...
}
you can solve this with your algo, but you must add one algorithm at the first your program until you declarate input. they are:
if(in1>in2) you must swap they before begin the proses. (you must keep this in your mind "in1 and in2, they are not string, but numbers").

hope this will be help. :wink: