11148 - Moliu Fractions
Posted: Sat Dec 30, 2006 6:37 pm
Do you have any very hard input ?
My program get WA, though i think it's correct :/

The Online Judge board
https://uva.onlinejudge.org/board/
https://uva.onlinejudge.org/board/viewtopic.php?f=37&t=13620
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;
}
Code: Select all
1
this_is_critical1/2 1/2
Code: Select all
1/4
Code: Select all
1
-there_can_be_cases_like_this 1/2 1/3
Code: Select all
1/6
Code: Select all
removed
Code: Select all
got AC
runerror would never execute if input and code is correct, so why it cause restricted function?FAQ wrote:artie, try to avoid all 'runerror(200)' in your code
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?
Code: Select all
3
asd-4/sdfs 3/4 asdad 2
2-3/sdfsdf sefd 1/4
1-szdc/4 abc 3
Code: Select all
1-1/2
1/4
3
Code: Select all
8
What is the product of 2 , 6/55 and 3-1/3 ?
A cookie weighs exactly 18-2/5 g. What is the weight of a packet of 12 cookies?
What is the product of 2 , 6/55 and 3-0/3 ?
A cookie weighs exactly 0-2/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 3-1/0 5/6 ?
A cookie weighs exactly 18-2/5 g. What is the weight of a packet of 12 cookies?
mangga mangga 0/6 mangga 5 mangga