### 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

Page **1** of **2**

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 :/

Posted: **Sat Dec 30, 2006 6:39 pm**

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;
}
```

Posted: **Sat Dec 30, 2006 7:15 pm**

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
```

Posted: **Sat Dec 30, 2006 9:24 pm**

My code:

My answer is 1/4

Code: Select all

```
Cut after acc ;]
```

Posted: **Sun Dec 31, 2006 7:38 am**

Input
Output

Code: Select all

```
1
-there_can_be_cases_like_this 1/2 1/3
```

Code: Select all

```
1/6
```

Posted: **Sun Dec 31, 2006 11:25 am**

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.

Posted: **Sun Dec 31, 2006 1:11 pm**

Thanks sohel ! ACC

Posted: **Fri Jan 05, 2007 4:32 am**

In the contest I got AC, but in the oj I got restricted function. What should I do?

Code: Select all

```
got AC
```

Posted: **Fri Jan 05, 2007 7:03 am**

artie, try to avoid all 'runerror(200)' in your code

Posted: **Fri Jan 05, 2007 8:54 am**

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

BTW, I removed it and got AC

Posted: **Fri Jan 05, 2007 2:22 pm**

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?

Posted: **Tue May 01, 2007 10:22 am**

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
asd-4/sdfs 3/4 asdad 2
2-3/sdfsdf sefd 1/4
1-szdc/4 abc 3
```

Posted: **Thu May 03, 2007 10:48 am**

output

Code: Select all

```
1-1/2
1/4
3
```

Posted: **Tue May 22, 2007 8:37 am**

Posted: **Fri Jul 06, 2007 3:42 pm**

Hi what the output for:

**INPUT**
Thanks before

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
```