Page 3 of 4

presentation error

Posted: Sat Nov 20, 2004 1:54 am
by gonzo
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]

Posted: Thu Jul 21, 2005 9:24 am
by emotional blind
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)

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;
}
thanks ..[/list]

Problem 275, does anyone have any trick I/O?

Posted: Sun Apr 02, 2006 8:15 am
by guma
I' ve just done the 202 problem and I thought the solution of the 275 would be very easy. I guess I was wrong :P
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:
0 5
My program shows:
.0
This expansion terminates.
Is this write? Is there any [other] trick I/O?

Thanks for your time,

and sorry for the bad english.

Posted: Sun Dec 24, 2006 4:58 am
by joy
I got PE several times, but do not understand why?
Please help

here is my code

Code: Select all

remove after acc...

Posted: Sun Dec 24, 2006 11:05 am
by rio
Try this input and you will know why.

Code: Select all

1 998
0 0

Posted: Sun Dec 24, 2006 4:39 pm
by joy
Thanks rio...

It is really a cool input!!

Posted: Thu Mar 15, 2007 2:50 pm
by algoJo
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?

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

}


Posted: Fri Mar 16, 2007 12:27 am
by Jan
Try the cases...

Input:

Code: Select all

451 536
529 668
736 767
0 0
Output:

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.
Hope these help.

Posted: Wed Dec 05, 2007 4:04 pm
by JCU

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;
}
Can some one help me?
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

Re: 275 why WA

Posted: Sun Dec 07, 2008 8:26 am
by abid_iut
Why I am getting WA
I think I pass correct output of all existing input
please someone check
here is the code:

Code: Select all

Removed
pls help :(

Re: 275

Posted: Sun Dec 07, 2008 8:51 am
by Articuno
Your program is not getting correct answer for all test cases. Try this case:

Code: Select all

1 2
And there is another thing:
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.
You forgot about this.
I think that will help. Good luck :-?

Re: 275

Posted: Sun Dec 07, 2008 3:29 pm
by abid_iut
hey Articuno
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.

Re: 275

Posted: Sun Dec 07, 2008 7:05 pm
by Articuno
Yes, your this output is correct. What about this case:

Code: Select all

2 2
it should be:

Code: Select all

.0
This expansion terminates.
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

Re: 275 WA

Posted: Sun Dec 07, 2008 9:07 pm
by abid_iut
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 :-? )

Code: Select all

removed

Re: 275

Posted: Mon Dec 08, 2008 4:52 pm
by Articuno
Well i have edited your code. It should be OK now:

Code: Select all

Removed
Hope it will help.
:)