202 - Repeating Decimals

All about problems in Volume 2. 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
brunokbcao
New poster
Posts: 4
Joined: Sun May 14, 2006 4:22 pm
Location: Recife, PE
Contact:

Post by brunokbcao » Wed May 24, 2006 1:08 am

0/15 = 0.0(0)
0 = number of digits in repeating cycle
.

It's it right!? I've got an beautiful "runtime error" :D

albet_januar
New poster
Posts: 35
Joined: Wed Apr 12, 2006 6:03 pm
Location: jakarta, indonesia
Contact:

Post by albet_januar » Mon Mar 12, 2007 5:29 pm

i really confuse.. why always get WA??...

Code: Select all

Accepted after re-code.. 
Thx for Jan.. I know my mistake..
Last edited by albet_januar on Sun Mar 18, 2007 11:51 am, edited 1 time in total.

Jan
Guru
Posts: 1334
Joined: Wed Jun 22, 2005 10:58 pm
Location: Dhaka, Bangladesh
Contact:

Post by Jan » Mon Mar 12, 2007 8:28 pm

Try the cases...

Input:

Code: Select all

41 468
1169 725
2962 465
2705 1146
2281 1828
961 492
Output:

Code: Select all

41/468 = 0.08(760683)
   6 = number of digits in repeating cycle

1169/725 = 1.61(2413793103448275862068965517)
   28 = number of digits in repeating cycle

2962/465 = 6.3(698924731182795)
   15 = number of digits in repeating cycle

2705/1146 = 2.3(60383944153577661431064572425828970331588132635253...)
   95 = number of digits in repeating cycle

2281/1828 = 1.24(78118161925601750547045951859956236323851203501094...)
   152 = number of digits in repeating cycle

961/492 = 1.95(32520)
   5 = number of digits in repeating cycle
Hope these help.
Ami ekhono shopno dekhi...
HomePage

dulon
New poster
Posts: 6
Joined: Sat Jun 23, 2007 6:03 am

Post by dulon » Sun Jun 24, 2007 6:24 am

Output:

Code: Select all

1/397 = 0.(00251889168765743073047858942065491183879093198992...)
   99 = number of digits in repeating cycle



  why you breaking it down in three lines? i got PE.  my output was like

[code]  
2099/1 = 2099.(0)
  1 = number of digits in repeating cycle

20/20 = 1.(0)
  1 = number of digits in repeating cycle

10/9 = 1.(1)
  1 = number of digits in repeating cycle

1001/998 = 1.0(0300601202404809619238476953907815631262525050100...)
  498 = number of digits in repeating cycle

890/901 = 0.(98779134295227524972253052164261931187569367369589...)
  208 = number of digits in repeating cycle

2999/928 = 3.23168(1034482758620689655172413793)
  28 = number of digits in repeating cycle

any idea?

Jan
Guru
Posts: 1334
Joined: Wed Jun 22, 2005 10:58 pm
Location: Dhaka, Bangladesh
Contact:

Post by Jan » Sun Jun 24, 2007 2:44 pm

Your output looks correctly formatted. You can post your code.
Ami ekhono shopno dekhi...
HomePage

dulon
New poster
Posts: 6
Joined: Sat Jun 23, 2007 6:03 am

Post by dulon » Mon Jun 25, 2007 12:18 am

okay i have fixed it.

so to print a new line you have to use "\n"?? "cout<<endl;" does not work??

Jan
Guru
Posts: 1334
Joined: Wed Jun 22, 2005 10:58 pm
Location: Dhaka, Bangladesh
Contact:

Post by Jan » Mon Jun 25, 2007 10:50 am

dulon wrote: so to print a new line you have to use "\n"?? "cout<<endl;" does not work??
Both should work.
Ami ekhono shopno dekhi...
HomePage

chinmoy kanti dhar
New poster
Posts: 19
Joined: Fri Jun 22, 2007 6:17 pm
Location: bangladesh

help me

Post by chinmoy kanti dhar » Thu Aug 23, 2007 7:14 pm

my program gives right output for all the input given in this page.but i am getting wr.

Code: Select all

  remove after AC
Last edited by chinmoy kanti dhar on Thu Aug 23, 2007 11:30 pm, edited 1 time in total.

Jan
Guru
Posts: 1334
Joined: Wed Jun 22, 2005 10:58 pm
Location: Dhaka, Bangladesh
Contact:

Post by Jan » Thu Aug 23, 2007 11:05 pm

Check the output...

Output:

Code: Select all

2943/2996 = 0.98(23097463284379172229639519359145527369826435246995...)
   318 = number of digits in repeating cycle
Hope it helps.
Ami ekhono shopno dekhi...
HomePage

chinmoy kanti dhar
New poster
Posts: 19
Joined: Fri Jun 22, 2007 6:17 pm
Location: bangladesh

Post by chinmoy kanti dhar » Thu Aug 23, 2007 11:28 pm

thanks jan.i have acepted now.

cppnewbiew
New poster
Posts: 1
Joined: Fri Dec 25, 2009 12:59 pm

202 RE...

Post by cppnewbiew » Fri Dec 25, 2009 1:05 pm

Hi, guys... Could somebody help me find what's wrong with my 202 code..
The system replay I have a Runtime error. But I can't find what's wrong.
I also increase the arraysize to 2000 but it still doesn't work.
BTW, my coding is not good. I'll appreciate if anyone can give any advice to revise my code.


//ACM 202 Repeating decimals
#include <iostream>
using namespace std;

int main(void){
int n1, n2;
int decimals[2000];
int remainder[2000];
int coef = 0;
int idx = 0;
bool found = false;
int length = 0; //Count the number of repeating cycle
int startIdx = 0;
while (cin>> n1>> n2){
idx = 0;
startIdx = 0;
length = 0;
found = false;
cout << n1 << "/" << n2 << " = " << static_cast<int>(n1/n2) << "." << flush;
while(!found){
if (n1/n2)
n1 = n1 - static_cast<int>(n1/n2) * n2;
n1 *= 10;
remainder[idx] = n1 % n2;
decimals[idx] = n1/n2;
// Find the repeat remainder
for (int i = 0; i != idx; i++) {
if (remainder == remainder[idx]){
found = true;
if (remainder[idx] == 0) // Means A|B
{
length = 1;
startIdx = idx;
found = true;
break;
}
else{
length = idx - i;
startIdx = i;
}
}
}
if (!found)
idx++;
}
if (length <= 1) // Means A|B
{
for (int k = 0; k != idx; k++)
cout << decimals[k];
cout << "(" << decimals[idx] << ")" << endl;
}
else { // Means A can not divided by B.. It has remainder
for (int k = 0; k != idx; k++) {
if (k == 50) {
cout << "...";
break;
}
if (k == startIdx)
cout << "(";
cout << decimals[k] ;
}
cout << ")" << endl;
}
cout << " " << length << " = number of digits in repeating cycles" << endl;
cout << endl;
}
//system("pause");
return 0;
}

hychin
New poster
Posts: 2
Joined: Sun Nov 14, 2010 1:01 pm

Re: 202 RE...

Post by hychin » Sun Nov 14, 2010 1:11 pm

The problem states that "None of the input integers exceeds 3000",
so, array size of 2000 is not enough but 3000 is enough.

No.47WK
New poster
Posts: 4
Joined: Thu Mar 31, 2011 1:25 pm

UVA 202

Post by No.47WK » Sun Apr 24, 2011 3:58 pm

I have tried all the test cases can be found in the site?and all i'o are correct?and I do not know what's wrong with my cod.
Help me,plz;
Or if you give me some critic I/OI will also appreciate if you give me some critic I/O
Here is my code

Code: Select all

#include<iostream>
#include<cstring>
#include<stdio.h>
#define SIZE 50000
#define MAX 50
using namespace std;
int main()
{
    int surplus[SIZE],digit[SIZE],place[SIZE],t,te,tem,temp,a,b;
    bool index=false;
    while(cin>>a>>b)
    {
        if(cin.eof())
            return 0;
        if(index)
            cout<<endl;
        t=a/b;
        te=a-t*b;
        te*=10;
        memset(surplus,0,sizeof(surplus));
        tem=1;
        surplus[te]=tem;
        while(1)
        {
            if(te<b)
            {
                te*=10;
                digit[tem]=0;
                ++tem;
            }
            else
            {
                digit[tem]=te/b;
                te=te%b;
                te*=10;
                ++tem;
            }
            if(surplus[te])
                break;
            surplus[te]=tem;
        }
        te=surplus[te];
        printf("%d/%d = %d.",a,b,t);
        temp=1;
        while(temp<te)
        {
            cout<<digit[temp];
            ++temp;
        }
        cout<<'(';
        if(tem-temp>49)
        {
            t=temp+50;
            while(temp<t)
            {
                cout<<digit[temp];
                ++temp;
            }
            printf("...)\n   %d = number of digits in repeating cycle\n",tem-te);
        }
        else
        {
            while(temp<tem)
            {
                cout<<digit[temp];
                ++temp;
            }
            printf(")\n   %d = number of digits in repeating cycle\n",tem-te);
        }
        index=true;
    }
    return 0;
} 
            
            
            
            

brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: UVA 202

Post by brianfry713 » Fri Sep 02, 2011 10:56 pm

Try adding a newline at the end of the output. It seems like that should cause a PE but for this problem it considers it a WA.
Check input and AC output for thousands of problems on uDebug!

brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: 202-why WA?

Post by brianfry713 » Fri Sep 02, 2011 11:00 pm

Check that you're using three spaces before the number not one - the forum software takes out extra spaces.

Also add a newline at the end of the output.
Last edited by brianfry713 on Fri Dec 16, 2011 8:14 pm, edited 1 time in total.
Check input and AC output for thousands of problems on uDebug!

Post Reply

Return to “Volume 2 (200-299)”