458 - The Decoder

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

mamun
A great helper
Posts: 286
Joined: Mon Oct 03, 2005 1:54 pm
Location: Bangladesh
Contact:

Post by mamun »

Did you really test your program with the sample I/O given?

yogeshgo05
New poster
Posts: 47
Joined: Sun Nov 27, 2005 12:43 pm

Post by yogeshgo05 »

i dont no what the err is actually,it gives right ans on my dev-c++;
plz help me.

sohel
Guru
Posts: 856
Joined: Thu Jan 30, 2003 5:50 am
Location: New York

Post by sohel »

since you are using ch = getchar(),
it implies you are getting a '\n' at the end of each line.

('\n' - 7) != '\n' and hence the problem.

add this line to your code,
if( ch == '\n' ) putchar('\n');
else {
your code.
}

tmdrbs6584
Learning poster
Posts: 98
Joined: Sat Jan 21, 2006 12:45 pm
Location: Busan,Corea(Republic of)

Maybe;

Post by tmdrbs6584 »

Maybe there is an error in array size

ferrizzi
New poster
Posts: 23
Joined: Thu Mar 30, 2006 5:42 pm
Location: Brazil

simplest code

Post by ferrizzi »

Code: Select all

#include<stdio.h>

int main()
{
   char ch, sub;
   while( (ch = getchar()) != EOF )
   {
       if(ch == '\n') printf("\n");
       else
         printf("%c", ch-7);
          
   }      
   return 0; 
}
I got AC with that :)
Regards,
[]'s
Andre

newton
Experienced poster
Posts: 162
Joined: Thu Jul 13, 2006 7:07 am
Location: Campus Area. Dhaka.Bangladesh
Contact:

Post by newton »

you must take the character into ascii form. then subtract 7.

ruba
New poster
Posts: 2
Joined: Mon Nov 06, 2006 12:13 pm
Location: dhaka
Contact:

494-why output limit exeeded?& 458-Time limit execeeded?

Post by ruba »

Hi,
this is my mail. Anyone plzzzz help me!


code for 494 :
#include<stdio.h>
#include<ctype.h>
void main()
{
int word,i;
char str[10000];
while(1)
{
word=0;
gets(str);
if(str[0]!='\0')
{
if(isalpha(str[0]))
word++;
for(i=0;str!='\0';i++)
{
if(str==' '||str=='\t')
if(isalpha(str[i+1]))
word++;

}
}
printf("%d\n",word);
}
}

Idonno why i am getting Output Limit Exceeded!
plz anyone,do let me know!!! :cry:


458 is an easy one but i am getting TLE!(why??)
code for 458:#include<stdio.h>
void main()
{
char str[100000];
int i;
while(1)
{
gets(str);
for(i=0;str!='\0';i++)
{
str=str-7;
printf("%c",str);
}
}
}

please someone HELP me! i just got stuck'n here... :cry:
[/u]
Important!!!

Solaris
Learning poster
Posts: 99
Joined: Sun Apr 06, 2003 5:53 am
Location: Dhaka, Bangladesh
Contact:

Post by Solaris »

There is no breaking condition in your "while" loop ... :P
try some thing like

Code: Select all

while(gets(str))
{
   ......
   ......
}
while(1) defines an infinite loop ... while(gets(str)) will break when it reaches End of Input File
Where's the "Any" key?

joy
New poster
Posts: 48
Joined: Wed Oct 18, 2006 1:00 pm
Location: Dhaka, Bangladesh
Contact:

Post by joy »

Both problem there are no breaking condition!!!

494 :
Read the problem statement carefully.
form kisui na ... class tai asol....
iF U hv d class u get the form....

&#40643;&#29577;&
New poster
Posts: 1
Joined: Thu Jan 18, 2007 10:09 am

I don't understand why it can't run Q458

Post by &#40643;&#29577;& »

#include<stdio.h>
#include<stdlib.h>
int main()
{
char c;
char *Output;
int i=0,j;

printf("please input words\t");

Output=(char*)malloc(100*sizeof(char));

while((c=getchar())!='\n')
{
Output=c-'J'+'C';
i++;
}

for(j=0;j<i;j++)
printf("%c",Output[j]);

printf("\n");

free(Output);

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 »

your code ran in my computer nicely

But if you you want to get AC in 458 you have modify your code

remove this line
printf("please input words\t");
and try to scan input until end of file (EOF)

this may help you

Best of luck
Akash chhoyar swopno
Dream to touch the sky

atm
New poster
Posts: 2
Joined: Sun Jan 21, 2007 2:33 pm

458..output limit exceeded???

Post by atm »

#include <iostream>
using namespace std;
int main()
{
char ch;
cin.get(ch);
while (ch != '\0')
{
if (ch == 10)
cout << ch;
else
cout << (static_cast<char>(ch-7));

cin.get(ch);
}
cout << '\n';
return 0;
}
my code works fine and im getting the correct output, except when i submit the code, im getting output limit exceeded...i dont understand why?!

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

Post by Debashis Maitra »

you should stop reading data when it get end of file (EOF).
Akash chhoyar swopno
Dream to touch the sky

jesun
New poster
Posts: 10
Joined: Tue Jan 01, 2008 10:55 pm

#458-got TLE,why?plz help

Post by jesun »

Regards.I got TLE for #458 but couldn't find the bug(s).Can anyboby help?
here is my code:

#include <iostream>
using namespace std;

int main()
{
char ch;
while((ch=cin.get())!=EOF)
{
if(ch==10)
cout<<"."<<endl;
else
{
ch-=7;
cout<<ch;
}
}
return 0;
}

Samiul
New poster
Posts: 36
Joined: Thu Dec 13, 2007 3:01 pm

Post by Samiul »

Use getchar() to read, from cin it is not reading the EOF(though it works fine on my compiler). This is giving you TLE.

Then remove the extra "." you are printing.

And don't open a new thread if there already exists one.

Post Reply

Return to “Volume 4 (400-499)”