10494  If We Were a Child Again
Moderator: Board moderators
10494  If We Were a Child Again
I got WA in this problem. But can't find bugs in my programs.
Someone please give me some test input/output to test my program.
thanks...
Someone please give me some test input/output to test my program.
thanks...
input :
output :
check with calculator.
Code: Select all
234098720432984729 / 234923845
24324 / 2342
check with calculator.

 Guru
 Posts: 834
 Joined: Wed May 29, 2002 4:11 pm
 Location: Wroclaw, Poland
 Contact:
try also input which are longer than i.e. 20 characters and second input number is near to 2^31
Best regards
DM
Best regards
DM
If you really want to get Accepted, try to think about possible, and after that  about impossible ... and you'll get, what you want ....
Born from ashes  restarting counter of problems (800+ solved problems)
Born from ashes  restarting counter of problems (800+ solved problems)
"The first one (number) may be arbitrarily long."
How long will it approximately be? 100 chrs? Or more?
How long will it approximately be? 100 chrs? Or more?
7th Contest of Newbies
Date: December 31st, 2011 (Saturday)
Time: 12:00  16:00 (UTC)
URL: http://uva.onlinejudge.org
Date: December 31st, 2011 (Saturday)
Time: 12:00  16:00 (UTC)
URL: http://uva.onlinejudge.org

 Guru
 Posts: 834
 Joined: Wed May 29, 2002 4:11 pm
 Location: Wroclaw, Poland
 Contact:
1000 is enough.
Try for these input :
Good Luck
angga888
Try for these input :
Code: Select all
0 / 2147483647 = 0
0 % 2147483647 = 0
2147483646 % 2147483647 = 2147483646
angga888
I got several WA at this problem! But I can't find anything wrong in my program. And here is my code, please tell me what is incorrect. Thank you!
Code: Select all
#include <iostream.h>
#include <math.h>
#include <iomanip.h>
int main()
{long double a,b,result;
char ch;
while (cin>>a)
{cin>>ch;
while (ch!='/' && ch!='%') cin>>ch;
cin>>b;
if (ch=='/') result=a/b;
else result=fmod(a,b);
cout<<setiosflags(ios::fixed);
cout<<setprecision(0)<<result<<endl;
}
return 1;
}

 Experienced poster
 Posts: 151
 Joined: Wed Aug 21, 2002 12:07 am
 Location: Seoul, Korea
 Contact:
Your program is surely wrong. _;
The input specifies that the first number to be arbitrarily large (Actually I think the test case contains numbers up to 1000 digits or so), but the long double variable's precision is not up to that.
You should implement bigint operation here. Read what is written so far.
The input specifies that the first number to be arbitrarily large (Actually I think the test case contains numbers up to 1000 digits or so), but the long double variable's precision is not up to that.
You should implement bigint operation here. Read what is written so far.
JongMan @ Yonsei

 Experienced poster
 Posts: 151
 Joined: Wed Aug 21, 2002 12:07 am
 Location: Seoul, Korea
 Contact:
Sure, why not.
You should use arrays to simulate the array as big integers. (when a[0] = 123 and a[1] = 456, these can be interpreted as 123456)
In case using strings as numbers are feasible, too.
Of course C or Pascal syntaxes do not support operations like these, so you should implement your own calculating functions like addition, subtraction, multiplication, .. etc.
There are algorithms to do operations of bigints faster than simulating hand operations (I believe there is one at Knuth's book), but in most cases, brute force operations are feasible.
For further info, try a search in this board using 'bigint' as the keyword.
Hope this helps.
You should use arrays to simulate the array as big integers. (when a[0] = 123 and a[1] = 456, these can be interpreted as 123456)
In case using strings as numbers are feasible, too.
Of course C or Pascal syntaxes do not support operations like these, so you should implement your own calculating functions like addition, subtraction, multiplication, .. etc.
There are algorithms to do operations of bigints faster than simulating hand operations (I believe there is one at Knuth's book), but in most cases, brute force operations are feasible.
For further info, try a search in this board using 'bigint' as the keyword.
Hope this helps.
JongMan @ Yonsei
Excuse me...
Can the result be stored in any data type (except BigInt)?
(I should think no........)
Can the result be stored in any data type (except BigInt)?
(I should think no........)
7th Contest of Newbies
Date: December 31st, 2011 (Saturday)
Time: 12:00  16:00 (UTC)
URL: http://uva.onlinejudge.org
Date: December 31st, 2011 (Saturday)
Time: 12:00  16:00 (UTC)
URL: http://uva.onlinejudge.org

 Guru
 Posts: 647
 Joined: Wed Jun 26, 2002 10:12 pm
 Location: Hong Kong and New York City
 Contact:
I didn't use a full BigInt class for this (because in a real contest, I wouldn't have brought one..)
But basically, you read in the first number as a string, the second number as an unsigned int, and then just output the thing in place.. it's pretty simple, since for %, it's obvious that the solution can fit in unsigned int, while you can use normal division rule..
But basically, you read in the first number as a string, the second number as an unsigned int, and then just output the thing in place.. it's pretty simple, since for %, it's obvious that the solution can fit in unsigned int, while you can use normal division rule..
10494
Hai guies I am fool at wa of 10494.
is my function wrong or where is wrong handling.
My code is
/*
/* @JUDGE_ID: XXXXXX 10494 C++ */
#include <stdio.h>
#include <string.h>
#define MAX 100000
unsigned long Modulas(char a[],unsigned long denomi)
{
unsigned long rim,len,i;
rim = (a[0]  48 )%denomi;
len = strlen(a);
for(i=1;i<len;i++)
rim = ( 10*rim + (a  48) )%denomi;
return rim;
}
char* String_divide(char a[],unsigned long denomi)
{
char res[MAX];
unsigned long rim,len,i,start,q=0;
rim =a[0]48;
len = strlen(a);
for(i=1;i<len;i++)
{
rim = rim*10 + a48;
if(rim>=denomi)
{
start = i;
break;
}
}
res[q++] = (rim/denomi) + 48;
rim = rim%denomi;
for(i=start+1;i<len;i++)
{
rim = ( 10*rim + (a  48) );
res[q++] = (rim/denomi) + 48;
rim = rim%denomi;
}
res[q]=0;
return res;
}
void main()
{
char a[MAX],sign[3],result[MAX];
unsigned long rim,denomi;
while(scanf("%s %s %lu",a,sign,&denomi)==3)
{
if(strcmp(sign,"%")==0)
{
rim = Modulas(a,denomi);
printf("%lu\n",rim);
}
else
{
strcpy(result,String_divide(a,denomi));
printf("%s\n",result);
}
}
}
/*@END_OF_SOURCE_CODE*/
*/
is my function wrong or where is wrong handling.
My code is
/*
/* @JUDGE_ID: XXXXXX 10494 C++ */
#include <stdio.h>
#include <string.h>
#define MAX 100000
unsigned long Modulas(char a[],unsigned long denomi)
{
unsigned long rim,len,i;
rim = (a[0]  48 )%denomi;
len = strlen(a);
for(i=1;i<len;i++)
rim = ( 10*rim + (a  48) )%denomi;
return rim;
}
char* String_divide(char a[],unsigned long denomi)
{
char res[MAX];
unsigned long rim,len,i,start,q=0;
rim =a[0]48;
len = strlen(a);
for(i=1;i<len;i++)
{
rim = rim*10 + a48;
if(rim>=denomi)
{
start = i;
break;
}
}
res[q++] = (rim/denomi) + 48;
rim = rim%denomi;
for(i=start+1;i<len;i++)
{
rim = ( 10*rim + (a  48) );
res[q++] = (rim/denomi) + 48;
rim = rim%denomi;
}
res[q]=0;
return res;
}
void main()
{
char a[MAX],sign[3],result[MAX];
unsigned long rim,denomi;
while(scanf("%s %s %lu",a,sign,&denomi)==3)
{
if(strcmp(sign,"%")==0)
{
rim = Modulas(a,denomi);
printf("%lu\n",rim);
}
else
{
strcpy(result,String_divide(a,denomi));
printf("%s\n",result);
}
}
}
/*@END_OF_SOURCE_CODE*/
*/
babor