10055 - Hashmat the Brave Warrior

All about problems in Volume 100. If there is a thread about your problem, please use it. If not, create one with its number in the subject.

Moderator: Board moderators

incin
New poster
Posts: 3
Joined: Tue Dec 24, 2002 5:52 pm

Post 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]
Ming Han
Learning poster
Posts: 77
Joined: Thu Jun 06, 2002 7:10 pm
Location: Singapore
Contact:

LONG LONG

Post 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?
:: HanWorks ::
incin
New poster
Posts: 3
Joined: Tue Dec 24, 2002 5:52 pm

Post 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?
ec3_limz
Learning poster
Posts: 79
Joined: Thu May 23, 2002 3:30 pm
Location: Singapore

Post 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.
Ming Han
Learning poster
Posts: 77
Joined: Thu Jun 06, 2002 7:10 pm
Location: Singapore
Contact:

Long Long

Post 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
:: HanWorks ::
Whinii F.
Experienced poster
Posts: 151
Joined: Wed Aug 21, 2002 12:07 am
Location: Seoul, Korea
Contact:

You CAN use double for this problem

Post 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..
thechaoshacker
New poster
Posts: 6
Joined: Wed Jan 22, 2003 9:19 pm
Contact:

WA

Post 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
Ming Han
Learning poster
Posts: 77
Joined: Thu Jun 06, 2002 7:10 pm
Location: Singapore
Contact:

ACM 10055

Post 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.
:: HanWorks ::
thechaoshacker
New poster
Posts: 6
Joined: Wed Jan 22, 2003 9:19 pm
Contact:

Accepted

Post by thechaoshacker »

Thanx !
I changed those two lines and it worked. What was going wrong ?
TheChaosHacker
Ming Han
Learning poster
Posts: 77
Joined: Thu Jun 06, 2002 7:10 pm
Location: Singapore
Contact:

Tips

Post by Ming Han »

You forgot to go to the next line after each output.
(cout<<tempa<<endl;)
:: HanWorks ::
Red Scorpion
Experienced poster
Posts: 192
Joined: Sat Nov 30, 2002 5:14 am

Post by Red Scorpion »

Try to use long long integer instead of using integer

Code: Select all

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

}
lendlice
New poster
Posts: 22
Joined: Thu Nov 21, 2002 10:50 am

10055(W.A)

Post 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]
Last edited by lendlice on Sun Mar 16, 2003 4:20 am, edited 2 times in total.
Hisoka
Experienced poster
Posts: 120
Joined: Wed Mar 05, 2003 10:40 am
Location: Indonesia

Post by Hisoka »

I think for this problem the result is |in2-in1| and you must use long long or double.
lendlice
New poster
Posts: 22
Joined: Thu Nov 21, 2002 10:50 am

Post by lendlice »

I use array
So I not to need use long or double.
Hisoka
Experienced poster
Posts: 120
Joined: Wed Mar 05, 2003 10:40 am
Location: Indonesia

Post 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:
Post Reply

Return to “Volume 100 (10000-10099)”