Page 4 of 12
Posted: Sun Mar 16, 2003 7:03 pm
by Adil
hello.
by the statement, the problemsetter means that the smaller of the inputs (when they are not equal) is always the number of hashmat's soldiers. so you have to decide which input indicates the number of hashmat's soldiers. (this, however is not really needed to solve this prob)
Posted: Mon Apr 14, 2003 4:28 am
by soyoja
Can I use unsigned integer data type?
I use unsined integer variable, but I got WA...
Anyone give me some hints?
Posted: Mon Apr 14, 2003 1:08 pm
by Hisoka
I think not, because for input you must greater than unsigned int.
for this problem you can use long long int, double, or string (like lendlice).
Posted: Fri Apr 18, 2003 1:14 am
by soyoja
At last, I got AC this problem. I use char array with my own "Big-Integer"
class. I think this problem fall under the big Integer problem category... ^^
thanks.
10055 - Can't use gthe function abs()
Posted: Sun Aug 17, 2003 7:16 am
by Joseph Kurniawan
With this code:
[c]
#include<stdio.h>
#include<math.h>
long long a,b;
void main(){
while(scanf("%lli %lli",&a,&b)!=EOF){
a-=b;
a=abs(a);
printf("%lli\n",a);
}
}
[/c]
I got WA.
But with this:
[c]
#include<stdio.h>
long long a,b;
void main(){
while(scanf("%lli %lli",&a,&b)!=EOF){
a-=b;
if(a<0) a=-a;
printf("%lli\n",a);
}
}
[/c]
I got AC.
Funny eh??
Posted: Sun Aug 17, 2003 3:19 pm
by shamim
the problem is with the data type.
I think abs can not handle the long long data type.
Posted: Mon Aug 18, 2003 9:45 am
by Joseph Kurniawan
Oh, I see. I suppose the function abs() can only work on int data type???
Posted: Mon Aug 18, 2003 4:59 pm
by UFP2161
In stdlib.h:
[c]int abs (int n);
long labs (long n);[/c]
If you're using C++ 3.2 (OJ uses 2.95, so this probably won't work here), you also have in cstdlib:
[cpp]long abs (long n);
long long abs (long long n);
long long llabs (long long n);[/cpp]
I had the same problem before
Posted: Tue Aug 19, 2003 8:16 pm
by mafattah
I had this same problem before. The problem would happen with int as well as with long long int. I think the reason is that in the standard C++ definition, abs is included in the <stdlib.h> or in <cstdlib>, but in MSVC++, they include it under <math.h>. It seems to be only another incompatibility from VC++.
P.S. I did not try including stdlib and sending to the judge, but that should be the standard.
Posted: Wed Aug 20, 2003 5:23 am
by Master
If you use abs then you have to include stdlib.h and if the parameter must be integer. And if you use double then use fabs.
In this problem you do not need to use abs or fabs. But you can use a if function.
M H Rasel
CUET Old Sailor
10055
Posted: Mon Aug 30, 2004 9:04 am
by someone
why this don't work i get a WA
[cpp]#include <cstdio>
#include <string>
using namespace std;
char buffer[1000],a[500],b[500];
void uradi();
int main ()
{
while (fgets(buffer,1000,stdin))
{
sscanf(buffer,"%s%s",a,b);
uradi();
};
return 0;
};
void uradi ()
{
char chTemp[2];
int n,x=0;
n=strlen(b);
bool blnBIG=false;
chTemp[0]='\0';
for (int i=0;i<(n-strlen(a-1));i++){buffer='0';}
buffer[n-strlen(a)]='\0';
strcat(buffer,a);
strcpy(a,buffer);
buffer[0]='\0';
for(int i=n-1;i>=0;i--)
{
if (blnBIG){x=-1;blnBIG=false;};
x+=b-'0';
if ((a-'0')>x){x+=10;blnBIG=true;}else blnBIG = false;
x-=a-'0';
sprintf(chTemp,"%i",x);
strcat(buffer,chTemp);
x=0;
};
for(int i=strlen(buffer)-1;i>-1;i--)
{
if (buffer!='0')break; else buffer=0;
};
for (int i=strlen(buffer)-1;i>=0;i--)
{
printf("%c",buffer);
};
printf("\n");
};[/cpp]
Posted: Mon Aug 30, 2004 11:42 am
by hiloshi
hi.
This problem is the simple subtraction problem.
You should only calculate deference between two integer(Not Big-Number).
But be careful for magnitude correlation of two integer.
If not clearly written about an input, you must not assume anything.
Posted: Mon Aug 30, 2004 12:35 pm
by Minilek
unsigned long long for this problem was enough (conversion specifier %llu).
that might have been overkill, but i knew it would work for sure and just did the first thing that came to my head that i knew would fit. : )
Posted: Sat Oct 16, 2004 3:46 am
by Qbens
Hm, I think problem isn't in <<endl; after cout . I submited something that:
Code: Select all
.....
while(!cin.eof())
{
cin>>liczba1>>liczba2;
if(liczba1<liczba2)
{
cout<<(liczba2-liczba1)<<endl;
}
if(liczba1>=liczba2)
{
cout<<(liczba1-liczba2)<<endl;
}
}
and I recived WA. When I changed
to
I get AC. Maybe someone know where is the problem.
Thanks
10055 - Can't understand why WA
Posted: Wed Nov 24, 2004 11:00 pm
by coolzero
[c]
#include <stdio.h>
#include <stdlib.h>
int main() {
long n1=0, n2=0;
while(scanf("%ld %ld\n", &n1, &n2) == 2)
printf("%ld\n", labs(n2-n1));
return 0;
}
[/c]
Input:
10 12
10 14
100 200
12 10
Output:
2
4
100
2
Can anyone help?
Tanks