275 - Expanding Fractions
Moderator: Board moderators
presentation error
I'm still getting Presentation Error. Can someone check my source code?
[c]
#include <stdio.h>
#include <stdlib.h>
int find(int *pole, int max) {
int i;
for(i=0; i<max; i++)
if(pole[max]==pole)
return i;
return -1;
}
int main() {
int numerator, denominator, a, i, j, x;
int nula;
int *rest;
int *solution;
int first=0;
while((scanf("%d %d", &numerator, &denominator)==2) &&(numerator!=0 || denominator!=0)){
nula=0;
a=denominator;
solution=(int *)malloc(denominator*sizeof(int));
rest=(int *)malloc(denominator*sizeof(int));
for(i=0; i<denominator; i++){
if(numerator==0 && i==0)
break;
if(numerator < denominator)
numerator = numerator * 10;
rest = numerator;
x = find(rest, i);
if(x==-1){
if(numerator%denominator==0) {
nula=1;
solution = numerator / denominator;
i++;
break;
}
else {
solution = numerator / denominator;
a = solution * denominator;
numerator = numerator - a;
}
}
else{
break;
}
}
if (first==0){
printf(".");
first=1;
}
else
printf("\n.");
if(numerator==0 && i==0)
printf("\nThis expansion terminates.\n");
else {
for(j=0; j<i; j++){
printf("%d", solution[j]);
if(j==48)
printf("\n");
if(j>48 && (((j-48)%50)==0))
printf("\n");
}
if(nula==1)
printf("\nThis expansion terminates.\n");
else
printf("\nThe last %d digits repeat forever.\n", i-x);
}
}
return 0;
}
[/c][/code]
[c]
#include <stdio.h>
#include <stdlib.h>
int find(int *pole, int max) {
int i;
for(i=0; i<max; i++)
if(pole[max]==pole)
return i;
return -1;
}
int main() {
int numerator, denominator, a, i, j, x;
int nula;
int *rest;
int *solution;
int first=0;
while((scanf("%d %d", &numerator, &denominator)==2) &&(numerator!=0 || denominator!=0)){
nula=0;
a=denominator;
solution=(int *)malloc(denominator*sizeof(int));
rest=(int *)malloc(denominator*sizeof(int));
for(i=0; i<denominator; i++){
if(numerator==0 && i==0)
break;
if(numerator < denominator)
numerator = numerator * 10;
rest = numerator;
x = find(rest, i);
if(x==-1){
if(numerator%denominator==0) {
nula=1;
solution = numerator / denominator;
i++;
break;
}
else {
solution = numerator / denominator;
a = solution * denominator;
numerator = numerator - a;
}
}
else{
break;
}
}
if (first==0){
printf(".");
first=1;
}
else
printf("\n.");
if(numerator==0 && i==0)
printf("\nThis expansion terminates.\n");
else {
for(j=0; j<i; j++){
printf("%d", solution[j]);
if(j==48)
printf("\n");
if(j>48 && (((j-48)%50)==0))
printf("\n");
}
if(nula==1)
printf("\nThis expansion terminates.\n");
else
printf("\nThe last %d digits repeat forever.\n", i-x);
}
}
return 0;
}
[/c][/code]
-
- A great helper
- Posts: 383
- Joined: Mon Oct 18, 2004 8:25 am
- Location: Bangladesh
- Contact:
I cant find out those inputs for which my program
doesn't give the correct answer
can anybody help me?
I give my code here
(Not for check the code
but only for check the critical input output
for which my program give incorrect output)
thanks ..[/list]
doesn't give the correct answer
can anybody help me?
I give my code here
(Not for check the code
but only for check the critical input output
for which my program give incorrect output)
Code: Select all
#include <iostream>
#include <stdio.h>
using namespace std;
#define max 30010
int num[max+1], n;
char digit[100000000];
int main (void)
{
int numerator, nominator;
int i, j, st, en, signal, repeat;cout<<"";
while(scanf("%d%d",&numerator,&nominator)==2){
if(!(numerator || nominator))break;
n=(numerator%nominator);
printf(".");
for(i=0;i<=nominator*10;i++)num[i]=0;
i=1;
signal=1;
repeat=1;
while(1){
if(num[n]){
st=num[n];
en=i;
if(n<nominator && num[n*10])st=num[n*10];
if(num[n]==1 && n<nominator && num[n*10] && num[n*10]!=1){
digit[i]='0';
i++;
en=i;
}
break;
}
if(!n){
digit[i]='0';
i++;
st=i-1;
en=i-1;
repeat=0;
break;
}
num[n]=i;
if(n<nominator){
n*=10;
if(num[n]){
st=num[n];
i++;
en=i;
if(n<nominator && num[n/10]>num[st]){
digit[i-1]='0';
}
if(num[n]==1 && n<nominator && num[n*10] && num[n*10]!=1){
digit[i]='0';
i++;
en=i;
}
break;
}
}
else if(num[n]){
st=num[n];
i++;
en=i;
if(n<nominator && num[n*10]){
st=num[n*10];
}
if(num[n]==1 && n<nominator && num[n*10] && num[n*10]!=1){
digit[i]='0';
i++;
en=i;
}
break;
}
num[n]=i;
while(n<nominator){
n*=10;
digit[i]='0';
i++;
if(num[n]){
st=num[n];
en=i;
if(n<nominator && num[n*10])st=num[n*10];
if(num[n]==1 && n<nominator && num[n*10]){
digit[i]='0';
i++;
en=i;
}
signal=0;
break;
}
num[n]=i;
}
if(!signal)break;
digit[i]=(n/nominator)+'0';
n=n%nominator;
i++;
}
for(i=1;i<st;i++){
if((i+50)%50 == 0){
cout<<endl;
}
cout<<digit[i];
}
for(i=st;i<en;i++){
if((i+50)%50 == 0){
cout<<endl;
}
cout<<digit[i];
}
if(repeat)
printf("\nThe last %d digits repeat forever.\n\n",en-st);
else
printf("\nThis expansion terminates.\n\n");
}
return 0;
}
Problem 275, does anyone have any trick I/O?
I' ve just done the 202 problem and I thought the solution of the 275 would be very easy. I guess I was wrong 
All the i/o that i got, wich by the way were only the sample ones, are passing. But the judge keep saying me WA.
What should be the output for something like:
Thanks for your time,
and sorry for the bad english.

All the i/o that i got, wich by the way were only the sample ones, are passing. But the judge keep saying me WA.
What should be the output for something like:
My program shows:0 5
Is this write? Is there any [other] trick I/O?.0
This expansion terminates.
Thanks for your time,
and sorry for the bad english.
I got PE several times, but do not understand why?
Please help
here is my code
Please help
here is my code
Code: Select all
remove after acc...
Last edited by joy on Sun Dec 24, 2006 4:42 pm, edited 1 time in total.
form kisui na ... class tai asol....
iF U hv d class u get the form....
iF U hv d class u get the form....
Try this input and you will know why.
Code: Select all
1 998
0 0
can somebody tell me why I got WA in this problem?
I've tried all the I/O set and it gave the same result?
any hints?
I've tried all the I/O set and it gave the same result?
any hints?
Code: Select all
#include<stdio.h>
#include<string.h>
#define MAX 30001
char arr[MAX];
int start,end;
int compute(void){
int i,j,k,len,I,flag=0;
len=strlen(arr);
for(i=0;i<len;i++)
{
for(j=i+1;j<len;j++)
{
if(arr[i]==arr[j])
{
start=i;end=j;
if(j-i==1)
{
for(k=j;k<len;k++)
if(arr[k]!=arr[j]) {flag=0;break;}
else flag=1;
}
else
{
I=j;
for(k=i;k<j;k++,I++)
if(arr[k]==arr[I]) flag=1;
else {flag=0;break;}
}
}
if(flag) return j-i;
}
if(flag) break;
}
return 0;
}
void main(){
int a,b,k,I=0,save,count=1,cas=0;
char kar;
while(scanf("%d %d",&a,&b)==2)
{
if(!a&&!b) break;
if(cas) printf("\n");
else cas=1;
I=0;count=1;
memset(arr,0,sizeof(arr));
save=a/b;
a%=b;
while(1)
{
a*=10;
k=a/b;
a%=b;
kar=k+'0';
arr[I]=kar;I++;
if(I==MAX-1) break;
}
k=compute();
printf(".");
if(save) printf("%d",save);
if(k==1)
{
if(arr[start]=='0'){for(I=0;I<end-1;I++,count++) {printf("%c",arr[I]);if(count==49) {printf("\n");count=-1;}}}
else for(I=0;I<end;I++,count++) {printf("%c",arr[I]);if(count==49) {printf("\n");count=-1;}}
}
else{
for(I=0;I<end;I++,count++)
{
printf("%c",arr[I]);
if(count==49){printf("\n");count=-1;}
}
}
if(k==1)
{
if(arr[start]!='0')printf("\nThe last %d digits repeat forever.\n",k);
else printf("\nThis expansion terminates.\n");
}
else printf("\nThe last %d digits repeat forever.\n",k);
count=1;
}
}
Try the cases...
Input:
Output:
Hope these help.
Input:
Code: Select all
451 536
529 668
736 767
0 0
Code: Select all
.841417910447761194029850746268656716
The last 33 digits repeat forever.
.7919161676646706586826347305389221556886227544910
17964071856287425149700598802395209580838323353293
41317365269461077844311377245508982035928143712574
8502994011976047904
The last 166 digits repeat forever.
.9595827900912646675358539765319426336375488917861
79921773142112125162972620599739243807040417209908
73533246414602346805736636245110821382007822685788
7874837027379400260756192
The last 174 digits repeat forever.
Ami ekhono shopno dekhi...
HomePage
HomePage
Code: Select all
#include<iostream>
using namespace std;
int main()
{
long long a,b;
long long q;
int m[100000] = {0};
int n[100000] = {0};
int i;
int jump;
int counter = 1;
while(cin >> a >> b)
{
if(a == 0 && b == 0)
break;
if(a%b == 0)
{
cout << ".";
cout << "\nThis expansion terminates.\n";
continue;
}
i = 0;
for(int j = 0;j < 100000;j++)
{
m[j] = 0;
n[j] = 0;
}
m[a%b] = 1;
a*=10;
counter = 1;
while(1)
{
if(a%b == 0)
{
n[i++] = a/b;
break;
}
else
{
if(m[a%b] == 0)
{
m[a%b] = ++counter;
n[i++] = a/b;
a%=b;
a*=10;
}
else
{
++counter;
n[i++] = a/b;
break;
}
}
}
jump = 0;
if(a%b == 0)
{
cout << ".";
for(int j = 0;j < i;j++)
{
jump++;
if(jump == 50)
{
cout << endl;
jump = 0;
}
cout << n[j];
}
cout << "\nThis expansion terminates.\n";
}
else
{
cout << ".";
for(int j = 0;j < i;j++)
{
jump++;
if(jump == 50)
{
cout << endl;
jump = 0;
}
cout << n[j];
}
cout << "\nThe last " << counter - m[a%b] << " digits repeat forever.\n\n";
}
}
return 0;
}
I test all case from this forum
but my answer is match all case
but i still get WA......
plz give me some advice
thanks a lot
I love coding ^^
Re: 275 why WA
Why I am getting WA
I think I pass correct output of all existing input
please someone check
here is the code:
pls help 
I think I pass correct output of all existing input
please someone check
here is the code:
Code: Select all
Removed

Last edited by abid_iut on Sun Dec 07, 2008 9:09 pm, edited 1 time in total.
i love to wait... wait for better... and better will come...
http://akanoi.webs.com/
http://akanoi.webs.com/
-
- Learning poster
- Posts: 78
- Joined: Sun Nov 30, 2008 5:00 pm
- Location: IUT-OIC, Dhaka, Bangladesh
Re: 275
Your program is not getting correct answer for all test cases. Try this case:
And there is another thing:
I think that will help. Good luck
Code: Select all
1 2
You forgot about this.multiple line expansions should each contain exactly 50 characters on each line(except the last line, which, of course, may be shorter) - that includes the beginning decimal point.
I think that will help. Good luck

Last edited by Articuno on Sun Dec 07, 2008 7:37 pm, edited 2 times in total.
May be tomorrow is a better day............ 

Re: 275
hey Articuno
I think I have solved those problems U mentioned but still WA
is there anymore thing to solve
and
is this OK
pls help.
I think I have solved those problems U mentioned but still WA
is there anymore thing to solve
and
Code: Select all
input:
1 2
output:
.5
This expansion terminates.
is this OK
pls help.
i love to wait... wait for better... and better will come...
http://akanoi.webs.com/
http://akanoi.webs.com/
-
- Learning poster
- Posts: 78
- Joined: Sun Nov 30, 2008 5:00 pm
- Location: IUT-OIC, Dhaka, Bangladesh
Re: 275
Yes, your this output is correct. What about this case:
it should be:
The rule about the newline is also applicable for the cases where the expansion terminates but there are more than 50 characters in a single line. Did you chechk this?
I have changed a little in your code and now it is AC. Try again.
Good luck.
if you are getting wrong answers after this, you can post your code. May be i can help
Code: Select all
2 2
Code: Select all
.0
This expansion terminates.
I have changed a little in your code and now it is AC. Try again.
Good luck.

if you are getting wrong answers after this, you can post your code. May be i can help
May be tomorrow is a better day............ 

Re: 275 WA
Hey Articuno my friend
I become very sad
You try to give me way
But I am getting WA
here is the modified code(need more modification
)
I become very sad
You try to give me way
But I am getting WA
here is the modified code(need more modification

Code: Select all
removed
Last edited by abid_iut on Mon Dec 08, 2008 5:31 pm, edited 1 time in total.
i love to wait... wait for better... and better will come...
http://akanoi.webs.com/
http://akanoi.webs.com/