408 - Uniform Generator

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

Moderator: Board moderators

Md.Arafat Hossain
New poster
Posts: 7
Joined: Fri Mar 02, 2007 10:20 am

OLE of 408

Post by Md.Arafat Hossain »

Why output limit exceed,please help me
here is my code:
#include<stdio.h>

int main(){

int step,seed=0,mod,i,k;

while(scanf("%d%d",&step,&mod)==2){
i=0;
seed=0;

k=seed;
seed=(seed+step)%mod;
i++;
while(seed!=k){
seed=(seed+step)%mod;
i++;}



printf("%10d%10d",step,mod);


if(mod==i)
printf(" Good Choice");
else
printf(" Bad Choice");

printf("\n");
}
return 0;
}

Debashis Maitra
Learning poster
Posts: 62
Joined: Sun Jul 09, 2006 8:31 am
Location: University of Dhaka
Contact:

Post by Debashis Maitra »

Change

Code: Select all

 while(scanf("%d%d",&step,&mod)==2)
To

Code: Select all

while(scanf("%d %d",&step,&mod)==2)
I think that will help you

And to avoid PE carefully read the output format
For each line of input, your program should print the STEP value right- justified in columns 1 through 10, the MOD value right-justified in columns 11 through 20 and either ``Good Choice" or ``Bad Choice" left-justified starting in column 25. The ``Good Choice" message should be printed when the selection of STEP and MOD will generate all the numbers between and including 0 and MOD-1 when MOD numbers are generated. Otherwise, your program should print the message ``Bad Choice". After each output test set, your program should print exactly one blank line.
Akash chhoyar swopno
Dream to touch the sky

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

Post by Jan »

Debashis Maitra wrote:Change

Code: Select all

while(scanf("%d%d",&step,&mod)==2)
To

Code: Select all

while(scanf("%d %d",&step,&mod)==2)
Debashis, both are correct.
Md.Arafat Hossain, your code looks ok. But your output format is not correct. There is no reason to get OLE. And don't open a new thread if there is one already. Use existing threads.
Ami ekhono shopno dekhi...
HomePage

Debashis Maitra
Learning poster
Posts: 62
Joined: Sun Jul 09, 2006 8:31 am
Location: University of Dhaka
Contact:

Post by Debashis Maitra »

Jan bhai you are right

But I dont understand why his problem is OLE

It should be PE
Akash chhoyar swopno
Dream to touch the sky

helloneo
Guru
Posts: 516
Joined: Mon Jul 04, 2005 6:30 am
Location: Seoul, Korea

Post by helloneo »

His code gives PE not OLE..

Md.Arafat Hossain
New poster
Posts: 7
Joined: Fri Mar 02, 2007 10:20 am

Post by Md.Arafat Hossain »

Thanks jan bhaia and Debashis.

ankit.arora
New poster
Posts: 11
Joined: Tue May 22, 2007 10:09 pm
Location: India

408 P.E.........Please help

Post by ankit.arora »

This is my code for prob 408 in which i m getting repeated P.E
please help!!!!

Code: Select all

#include<iostream>
using namespace std;
int main()
{
           int step,mod;
           while(cin>>step>>mod)             
           {
                   int arr[100010],set=0,prev,i,j,count,seed;
                   
                   for(j=0;j<mod;j++)
                   arr[j]=0;
                   prev=0;
                   count=0;
                   
                   while(1)
                   {
                           if(count==mod)
                           {
                                  set=1;
                                  break;
                           }        
                           seed=(prev+step)%mod;
                           if(arr[seed]!=1)
                           {
                                  arr[seed]=1;
                                  prev=seed;
                                  count++;
                           }
                           else
                           break;
                   }
                   cout<<"    ";
                   i=100000;
                   while(i>step)
                   {
                         cout<<" ";
                         i/=10;
                   }
                   cout<<step;      
                   cout<<"    ";
                   i=100000;
                   while(i>mod)
                   {
                         cout<<" ";
                         i/=10;
                   }
                   cout<<mod;      
                   if(set==1)
                   cout<<"    Good Choice\n\n";
                   else
                   cout<<"    Bad Choice\n\n";
           }
}
[/code]

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

Post by Jan »

Search the board and post your problem in an existing thread.
Ami ekhono shopno dekhi...
HomePage

ankit.arora
New poster
Posts: 11
Joined: Tue May 22, 2007 10:09 pm
Location: India

P.E. in 408

Post by ankit.arora »

I am getting P.E. in 408...... someone please help!

Code: Select all

#include<iostream>
using namespace std;
int main()
{
           int step,mod;
           while(cin>>step>>mod)             
           {
                   int arr[100010],set=0,prev,i,j,count,seed;
                   
                   for(j=0;j<mod;j++)
                   arr[j]=0;
                   prev=0;
                   count=0;
                   
                   while(1)
                   {
                           if(count==mod)
                           {
                                  set=1;
                                  break;
                           }       
                           seed=(prev+step)%mod;
                           if(arr[seed]!=1)
                           {
                                  arr[seed]=1;
                                  prev=seed;
                                  count++;
                           }
                           else
                           break;
                   }
                   cout<<"    ";
                   i=100000;
                   while(i>step)
                   {
                         cout<<" ";
                         i/=10;
                   }
                   cout<<step;     
                   cout<<"    ";
                   i=100000;
                   while(i>mod)
                   {
                         cout<<" ";
                         i/=10;
                   }
                   cout<<mod;     
                   if(set==1)
                   cout<<"    Good Choice\n\n";
                   else
                   cout<<"    Bad Choice\n\n";
           }
}

That's Good
New poster
Posts: 2
Joined: Sat May 19, 2007 11:53 pm

PE in 408

Post by That's Good »

Ankit To avoid the presentation error , Just look out in which coumn your code is being printed. To get help you can copy the spaces from the problem.

**printf("%10ld%10ld Good Choice\n"):**
***Use four space before Good/Bad Choice***


this code might be helpful.
Try it out. :wink:
Everything have a solution. Perhaps You don't know.

NaIx
New poster
Posts: 4
Joined: Sat Jun 02, 2007 5:49 pm
Location: indonesia

WA helppp

Post by NaIx »

i submit my code but i'm get WA... i didn't know where the problem... so somebody help plsss..... tq

Code: Select all

#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<cstring>
#define MAX 100000

long int seed[MAX];
long int temp[MAX];

int main()
{
    long int step, mod, cek, i;
//    freopen("in.txt","r",stdin);
//    freopen("out.txt","w",stdout);
    while(scanf("%ld %ld",&step,&mod)==2)
    {
        memset(seed,0,sizeof(seed));
        memset(temp,0,sizeof(temp));
        for(i=1;i<mod;i++)
        {
            seed[i]=(seed[i-1]+step)%mod;
            temp[seed[i]]=1; 
        }
        for(i=1;i<mod;i++)
        {
            if(temp[i]==1)
                cek=1;
            else cek=0;
        }
        printf("%10ld%10ld    ",step,mod);
        if(!cek) printf("Bad Choice\n\n");
        else printf("Good Choice\n\n");
    }
    return 0;
}
Last edited by NaIx on Fri Jun 29, 2007 1:01 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 »

Your output format is not correct.
Ami ekhono shopno dekhi...
HomePage

seeking help
New poster
Posts: 1
Joined: Mon Jan 14, 2008 8:33 pm
Location: dhaka

408....RE .....anyone plz help

Post by seeking help »

my code is giving re. i couldnt find out the reason why?anyone plz help me to understand...

include<stdio.h>
#include<string.h>

int main()
{
long int step,modd,seed,seed1,cnt;

while(scanf("%ld%ld",&step,&modd)==2)
{
seed=0;
cnt=0;

seed1=(seed+step)%modd;
cnt++;

while(1)
{
if(seed1==0)
break;

seed1=(seed1+step)%modd;
cnt++;

}
printf("%10ld%10ld",step,modd);

if(cnt==modd)
printf(" Good Choice");

else
printf(" Bad Choice");

printf("\n\n");

}

return 1;

}

mf
Guru
Posts: 1244
Joined: Mon Feb 28, 2005 4:51 am
Location: Zürich, Switzerland
Contact:

Post by mf »

main() should return 0.

Non-zero exit code conventionally means an error.

AcmNightivy
New poster
Posts: 36
Joined: Tue Dec 04, 2007 10:20 am

408WA..Help

Post by AcmNightivy »

Could someone help to find my mistake..i get puzzled..Thanks..And why
gcd (step, mod) == 1 is a Good Choice(found in other thread)..

Code: Select all

#include <stdio.h>
#include "string.h"

bool exist[10000001];

int main ()
{
	int step, mod, l, i;
	bool flag;
	bool first = true;

	while (scanf ("%d%d", &step, &mod) != EOF)	//(L+step) % mod
	{
		if (first)
			first = false;
		else
			printf ("\n");

		flag = true;
		l = 0;
		memset (exist, 0, 10000001);

		exist[l] = true;
		l = (step + l) % mod;

		while (!exist[l])
		{
			exist[l] = true;
			l = (step + l) % mod;		
		}

		printf ("%10d%10d    ", step, mod);

		for (i = 0; i < mod; i++)
			if (exist[i] == false)
			{
				flag = false;
				break;
			}

		if (flag)
			printf ("Good Choice\n");
		else
			printf ("Bad Choice\n");
	}
	return 0;
}

Post Reply

Return to “Volume 4 (400-499)”