202 - Repeating Decimals
Moderator: Board moderators
-
- New poster
- Posts: 4
- Joined: Sun May 14, 2006 4:22 pm
- Location: Recife, PE
- Contact:
0/15 = 0.0(0)
0 = number of digits in repeating cycle.
It's it right!? I've got an beautiful "runtime error"
0 = number of digits in repeating cycle.
It's it right!? I've got an beautiful "runtime error"
Look at my status:
http://acm.uva.es/problemset/usersjudge.php?user=1754
http://acm.uva.es/problemset/usersjudge.php?user=1754
-
- New poster
- Posts: 35
- Joined: Wed Apr 12, 2006 6:03 pm
- Location: jakarta, indonesia
- Contact:
i really confuse.. why always get WA??...
Thx for Jan.. I know my mistake..
Code: Select all
Accepted after re-code..
Last edited by albet_januar on Sun Mar 18, 2007 11:51 am, edited 1 time in total.
Try the cases...
Input:
Output:
Hope these help.
Input:
Code: Select all
41 468
1169 725
2962 465
2705 1146
2281 1828
961 492
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
Ami ekhono shopno dekhi...
HomePage
HomePage
Output:
any idea?
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
Both should work.dulon wrote: so to print a new line you have to use "\n"?? "cout<<endl;" does not work??
Ami ekhono shopno dekhi...
HomePage
HomePage
-
- New poster
- Posts: 19
- Joined: Fri Jun 22, 2007 6:17 pm
- Location: bangladesh
help me
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.
Check the output...
Output:
Hope it helps.
Output:
Code: Select all
2943/2996 = 0.98(23097463284379172229639519359145527369826435246995...)
318 = number of digits in repeating cycle
Ami ekhono shopno dekhi...
HomePage
HomePage
-
- New poster
- Posts: 19
- Joined: Fri Jun 22, 2007 6:17 pm
- Location: bangladesh
-
- New poster
- Posts: 1
- Joined: Fri Dec 25, 2009 12:59 pm
202 RE...
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;
}
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;
}
Re: 202 RE...
The problem states that "None of the input integers exceeds 3000",
so, array size of 2000 is not enough but 3000 is enough.
so, array size of 2000 is not enough but 3000 is enough.
UVA 202
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
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;
}
-
- Guru
- Posts: 5947
- Joined: Thu Sep 01, 2011 9:09 am
- Location: San Jose, CA, USA
Re: UVA 202
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!
-
- Guru
- Posts: 5947
- Joined: Thu Sep 01, 2011 9:09 am
- Location: San Jose, CA, USA
Re: 202-why WA?
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.
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!