408 - Uniform Generator
Moderator: Board moderators
-
- New poster
- Posts: 7
- Joined: Fri Mar 02, 2007 10:20 am
OLE of 408
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;
}
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;
}
-
- Learning poster
- Posts: 62
- Joined: Sun Jul 09, 2006 8:31 am
- Location: University of Dhaka
- Contact:
Change
To
I think that will help you
And to avoid PE carefully read the output format
Code: Select all
while(scanf("%d%d",&step,&mod)==2)
Code: Select all
while(scanf("%d %d",&step,&mod)==2)
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
Dream to touch the sky
Debashis, both are correct.Debashis Maitra wrote:ChangeToCode: Select all
while(scanf("%d%d",&step,&mod)==2)
Code: Select all
while(scanf("%d %d",&step,&mod)==2)
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
HomePage
-
- Learning poster
- Posts: 62
- Joined: Sun Jul 09, 2006 8:31 am
- Location: University of Dhaka
- Contact:
-
- New poster
- Posts: 7
- Joined: Fri Mar 02, 2007 10:20 am
-
- New poster
- Posts: 11
- Joined: Tue May 22, 2007 10:09 pm
- Location: India
408 P.E.........Please help
This is my code for prob 408 in which i m getting repeated P.E
please help!!!!
[/code]
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";
}
}
-
- New poster
- Posts: 11
- Joined: Tue May 22, 2007 10:09 pm
- Location: India
P.E. in 408
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";
}
}
-
- New poster
- Posts: 2
- Joined: Sat May 19, 2007 11:53 pm
PE in 408
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.
**printf("%10ld%10ld Good Choice\n"):**
***Use four space before Good/Bad Choice***
this code might be helpful.
Try it out.

Everything have a solution. Perhaps You don't know.
WA helppp
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.
-
- New poster
- Posts: 1
- Joined: Mon Jan 14, 2008 8:33 pm
- Location: dhaka
408....RE .....anyone plz 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;
}
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;
}
-
- New poster
- Posts: 36
- Joined: Tue Dec 04, 2007 10:20 am
408WA..Help
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)..
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;
}