11148  Moliu Fractions
Moderator: Board moderators
11148  Moliu Fractions
Do you have any very hard input ? My program get WA, though i think it's correct :/

 Experienced poster
 Posts: 105
 Joined: Wed May 25, 2005 7:23 am
even i am getting WA.
here is my code.
here is my code.
Code: Select all
#include<stdio.h>
#include<ctype.h>
#include<string.h>
char arr[1001];
unsigned long long gnum, gden;
unsigned long long
gcd (unsigned long long m, unsigned long long n)
{
if (n == 1)
return 1;
if (m % n == 0)
return n;
return gcd (n, m % n);
}
void
init (void)
{
char *y, *s, *t;
unsigned long cnt, fl, p1, p2, p3, num, den;
fgets (arr, 1000, stdin);
gnum = 1ULL;
gden = 1ULL;
s = arr;
cnt = 0;
while ((y = strtok (s, " ")) != NULL)
{
s = NULL;
t = y;
fl = 0;
p1 = 0;
p2 = 0;
p3 = 0;
if (isdigit (*t))
{
while (*t && isdigit (*t))
{
fl = 1;
p1 *= 10;
p1 += *t  '0';
t++;
}
if (*t == '')
{
fl = fl + 3;
p3 = 0;
t++;
while (*t && isdigit (*t))
{
p3 *= 10;
p3 += *t  '0';
t++;
}
}
if (*t == '/')
{
t++;
fl = fl + 5;
p2 = 0;
while (*t && isdigit (*t))
{
p2 *= 10;
p2 += *t  '0';
t++;
}
}
if (fl == 1)
{
num = p1;
den = 1;
}
if (fl == 6)
{
num = p1;
den = p2;
}
if (fl == 9)
{
den = p1 * p2;
num = den + p3;
den = p2;
}
gnum *= num;
gden *= den;
}
}
return;
}
int
main ()
{
int no;
unsigned long long k;
fgets (arr, 1000, stdin);
no = strtoul (arr, NULL, 10);
while (no)
{
init ();
k = 1;
k = gcd (gnum, gden);
if (k >= 1)
{
gnum /= k;
gden /= k;
}
if (gden == 1)
{
printf ("%llu\n", gnum);
}
else if (gnum < gden)
{
printf ("%llu/%llu\n", gnum, gden);
}
else
{
printf ("%llu%llu/%llu\n", gnum / gden, gnum % gden, gden);
}
}
return 0;
}
Aha..
I think you made the same mistake that I initially made. Had to debug my code for 30 mins to find it.
input
output
I think you made the same mistake that I initially made. Had to debug my code for 30 mins to find it.
input
Code: Select all
1
this_is_critical1/2 1/2
Code: Select all
1/4
My code:
My answer is 1/4
Code: Select all
Cut after acc ;]
Last edited by Spykaj on Sun Dec 31, 2006 1:11 pm, edited 2 times in total.
Input
Output
Code: Select all
1
there_can_be_cases_like_this 1/2 1/3
Code: Select all
1/6
Hi. I am new here.
I got the same problem. It's WA.
(at first my code is very short, but after reading that there can be many tricky cases I changed it much and it became this long )
sorry. I remove my code.
My code doing stupid things in cases like : "cases_like  2  2  2 / 2 !"
I will repair it
Thank you very much.
I got the same problem. It's WA.
(at first my code is very short, but after reading that there can be many tricky cases I changed it much and it became this long )
Code: Select all
removed
My code doing stupid things in cases like : "cases_like  2  2  2 / 2 !"
I will repair it
Thank you very much.
Last edited by indogila on Mon Jan 01, 2007 6:05 am, edited 1 time in total.
In the contest I got AC, but in the oj I got restricted function. What should I do?
Code: Select all
got AC
Last edited by artie on Fri Jan 05, 2007 7:29 am, edited 1 time in total.
I guess Restrict Function verdict is given in the compile stage.artie wrote:runerror would never execute if input and code is correct, so why it cause restricted function?
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

 Learning poster
 Posts: 54
 Joined: Mon Jan 02, 2006 3:06 am
 Location: Dhaka,Bangladesh
 Contact:
i am getting RE in this problem.....can anyone tell me the correct output for the following input
thanx in advance.
Code: Select all
3
asd4/sdfs 3/4 asdad 2
23/sdfsdf sefd 1/4
1szdc/4 abc 3
Sanjana
output
Code: Select all
11/2
1/4
3
kolpobilashi, I can tell you that there are NO cases like those...
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
Hi what the output for:
INPUT
Thanks before
INPUT
Code: Select all
8
What is the product of 2 , 6/55 and 31/3 ?
A cookie weighs exactly 182/5 g. What is the weight of a packet of 12 cookies?
What is the product of 2 , 6/55 and 30/3 ?
A cookie weighs exactly 02/5 g. What is the weight of a packet of 12 cookies?
there_can_be_cases_like_this 3/2 1/345
What is the product of 2 , 6/0 and 31/0 5/6 ?
A cookie weighs exactly 182/5 g. What is the weight of a packet of 12 cookies?
mangga mangga 0/6 mangga 5 mangga