Page 3 of 5

Posted: Mon Jan 30, 2006 1:07 pm
by mamun
Did you really test your program with the sample I/O given?

Posted: Mon Jan 30, 2006 1:43 pm
by yogeshgo05
i dont no what the err is actually,it gives right ans on my dev-c++;
plz help me.

Posted: Mon Jan 30, 2006 3:11 pm
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.
}

Maybe;

Posted: Thu Feb 09, 2006 1:08 pm
by tmdrbs6584
Maybe there is an error in array size

simplest code

Posted: Sat Apr 08, 2006 10:42 pm
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 :)

Posted: Sat Aug 05, 2006 3:53 pm
by newton
you must take the character into ascii form. then subtract 7.

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

Posted: Mon Nov 06, 2006 1:08 pm
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]

Posted: Mon Nov 06, 2006 8:22 pm
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

Posted: Mon Nov 06, 2006 9:04 pm
by joy
Both problem there are no breaking condition!!!

494 :
Read the problem statement carefully.

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

Posted: Thu Jan 18, 2007 10:15 am
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;
}

Posted: Thu Jan 18, 2007 4:36 pm
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

458..output limit exceeded???

Posted: Sun Jan 21, 2007 3:19 pm
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?!

Posted: Sun Jan 21, 2007 8:29 pm
by Debashis Maitra
you should stop reading data when it get end of file (EOF).

#458-got TLE,why?plz help

Posted: Tue Jan 01, 2008 11:20 pm
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;
}

Posted: Thu Jan 03, 2008 7:46 am
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.