11148 - Moliu Fractions

All about problems in Volume 111. If there is a thread about your problem, please use it. If not, create one with its number in the subject.

Moderator: Board moderators

User avatar
Spykaj
New poster
Posts: 47
Joined: Sun May 21, 2006 12:13 pm

11148 - Moliu Fractions

Post by Spykaj » Sat Dec 30, 2006 6:37 pm

Do you have any very hard input ? :( My program get WA, though i think it's correct :/

temper_3243
Experienced poster
Posts: 105
Joined: Wed May 25, 2005 7:23 am

Post by temper_3243 » Sat Dec 30, 2006 6:39 pm

even i am getting WA.
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;
}



User avatar
sohel
Guru
Posts: 856
Joined: Thu Jan 30, 2003 5:50 am
Location: New York

Post by sohel » 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

Code: Select all

1
this_is_critical1/2 1/2
output

Code: Select all

1/4

User avatar
Spykaj
New poster
Posts: 47
Joined: Sun May 21, 2006 12:13 pm

Post by Spykaj » Sat Dec 30, 2006 9:24 pm

My code:

Code: Select all

Cut after acc ;]
My answer is 1/4 :(
Last edited by Spykaj on Sun Dec 31, 2006 1:11 pm, edited 2 times in total.

User avatar
sohel
Guru
Posts: 856
Joined: Thu Jan 30, 2003 5:50 am
Location: New York

Post by sohel » Sun Dec 31, 2006 7:38 am

Input

Code: Select all

1
-there_can_be_cases_like_this 1/2 1/3
Output

Code: Select all

1/6

indogila
New poster
Posts: 2
Joined: Sun Dec 31, 2006 11:19 am

Post by indogila » 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 :()

Code: Select all

removed
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.
Last edited by indogila on Mon Jan 01, 2007 6:05 am, edited 1 time in total.

User avatar
Spykaj
New poster
Posts: 47
Joined: Sun May 21, 2006 12:13 pm

Post by Spykaj » Sun Dec 31, 2006 1:11 pm

Thanks sohel ! :) ACC

artie
New poster
Posts: 8
Joined: Sun Dec 31, 2006 11:56 am
Location: Russia

Post by artie » 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
Last edited by artie on Fri Jan 05, 2007 7:29 am, edited 1 time in total.

FAQ
Learning poster
Posts: 84
Joined: Wed Jan 28, 2004 6:23 pm

Post by FAQ » Fri Jan 05, 2007 7:03 am

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

artie
New poster
Posts: 8
Joined: Sun Dec 31, 2006 11:56 am
Location: Russia

Post by artie » Fri Jan 05, 2007 8:54 am

FAQ wrote:artie, try to avoid all 'runerror(200)' in your code
runerror would never execute if input and code is correct, so why it cause restricted function?

BTW, I removed it and got AC
per aspera ad astra

Observer
Guru
Posts: 570
Joined: Sat May 10, 2003 4:20 am
Location: Hong Kong

Post by Observer » Fri Jan 05, 2007 2:22 pm

artie wrote:runerror would never execute if input and code is correct, so why it cause restricted function?
I guess Restrict Function verdict is given in the compile stage.
7th Contest of Newbies
Date: December 31st, 2011 (Saturday)
Time: 12:00 - 16:00 (UTC)
URL: http://uva.onlinejudge.org

kolpobilashi
Learning poster
Posts: 54
Joined: Mon Jan 02, 2006 3:06 am
Location: Dhaka,Bangladesh
Contact:

Post by kolpobilashi » 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

Code: Select all

3
asd-4/sdfs 3/4 asdad 2
2-3/sdfsdf sefd 1/4
1-szdc/4 abc 3
thanx in advance.
Sanjana

mmonish
Experienced poster
Posts: 109
Joined: Sun Mar 11, 2007 2:55 pm
Location: SUST

Post by mmonish » Thu May 03, 2007 10:48 am

output

Code: Select all

1-1/2
1/4
3

Observer
Guru
Posts: 570
Joined: Sat May 10, 2003 4:20 am
Location: Hong Kong

Post by Observer » Tue May 22, 2007 8:37 am

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

User avatar
algoJo
New poster
Posts: 37
Joined: Sun Dec 17, 2006 9:02 am

Post by algoJo » Fri Jul 06, 2007 3:42 pm

Hi what the output for:
INPUT

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
Thanks before :)

Post Reply

Return to “Volume 111 (11100-11199)”