Page 1 of 2
10293
Posted: Sat Jul 06, 2002 3:38 pm
by FT
My program got Time Limit Exceeded.
Any one can help me.
Correct my mistake please.
Thank you.
Code: Select all
[cpp]
#include<iostream.h>
#include<math.h>
#include<stdio.h>
#define in cin
int len[31];
void main()
{
char ch;
int ltemp;
int i,flag;
while(in.get(ch)){
for(i=0;i<31;i++) len[i]=0;
ltemp=0;
flag=0;
while(ch!='#'){
if(ch==' '||ch=='?'||ch=='!'||ch==','||ch=='.'){
len[ltemp]++;
if(flag) flag=0;
ltemp=0;
}
if(ch=='-'){
flag=1;
}
if(ch=='\n'&&!flag){
len[ltemp]++;
if(flag) flag=0;
ltemp=0;
}
if((ch>='A'&&ch<='Z')||(ch>='a'&&ch<='z')){
ltemp++;
}
in.get(ch);
}
for(i=1;i<31;i++)
if(len[i]) cout<<i<<" "<<len[i]<<endl;
cout<<endl;
in.get(ch);
if(ch==EOF) break;
}
}
[/cpp]
Posted: Sat Jul 06, 2002 4:24 pm
by Picard
your inner cycle stops only when ch=='#' but not for ch==EOF which can occur for example when the last '#' is followed by a newline.
TLE
Posted: Sat Nov 01, 2003 8:34 pm
by Sajid
i checked both for '#' and EOF.. but why TLE ?
Posted: Sat Nov 08, 2003 4:21 pm
by Joseph Kurniawan
Well, you can try scanf() and printf() instead of cin and cout since these two I/O handler of C++ works quite slow compared to C I/O handler.
Hope it helps!!

Posted: Sat Nov 08, 2003 4:27 pm
by Sajid
I dont use cin or cout,
since I am comfortable with C.
Posted: Mon Dec 01, 2003 3:40 pm
by sohel
I got TLE too.
But later by trial and error I managed to figure out that there are some extra new lines at the end of the last block.

10293 w.a(Word Length and Frequency)critical i\o needed
Posted: Mon May 01, 2006 8:48 pm
by tuman
hi guys, i m getting wrong answer

in this problem for a long time. Plz provide some input and output so that i can justify my code.
Thanks in advance......and i m waiting for someones reply.
I/O
Posted: Wed May 03, 2006 7:24 pm
by jan_holmes
Try this Input :
hyper!..Goal,terM,cham-
pion. Try it A!g!a!iA.N
Thank-
s
you.
#
The output should be :
1 4
2 2
3 2
4 2
5 1
6 1
8 1
10293 - Word Length and Frequency
Posted: Mon Jul 10, 2006 10:53 pm
by unaben
I got run time error on this problem.

Could someone please help me.
Here is my code:
Removed
Posted: Mon Jul 10, 2006 11:02 pm
by unaben
I got AC now

Posted: Tue Oct 17, 2006 3:58 am
by tuman
After a long time, i ve found this post is replied and i got it.
Thanx i got it............AC

Posted: Sun Jan 14, 2007 8:22 pm
by yiuyuho
Well, I am getting P.E. now, may be that's the reason (I ended up reading the extra lines as a new input case)!!
Newlines after the last case!!!
Posted: Wed Feb 28, 2007 6:29 pm
by nymo
Hi, I also got P.E. and after reading this post, I changed my code to handle newlines after the last case... it is ACC now. If you got P.E., this change is worth trying. Thanks to Sohel for pointing out this.
Posted: Sun Apr 01, 2007 7:14 pm
by mohsincsedu
Need more IO...
I Got PE .....
Thanks in advance
Posted: Sun Apr 22, 2007 8:03 am
by algoJo
Hi, I got RE for this problem...
any hints??
Thanks..
Code: Select all
#include<stdio.h>
#include<string.h>
#define MAX 100
char arr[10000][MAX];
int res[50];
void compute(int L){
int i,j,len,flag=0;
int temp=0;
for(i=0;i<L;i++)
{
len=strlen(arr[i]);
if(!flag)
{
res[temp]++;temp=0;
}
for(j=0;j<len;j++)
{
if(arr[i][j]=='-'||arr[i][j]=='\'') flag=1;
else if(arr[i][j]!=' '&&arr[i][j]!='?'&&arr[i][j]!='!'&&arr[i][j]!=','&&arr[i][j]!='.') {temp++;flag=0;}
else
{
flag=0;
res[temp]++;temp=0;
}
if(j+1>=len&&!flag)
{
flag=0;
res[temp]++;temp=0;
}
}
}
for(i=1;i<50;i++)
if(res[i]) printf("%d %d\n",i,res[i]);
}
void main(){
char line[MAX];
int I=1;
while(gets(line))
{
memset(arr,0,sizeof(arr));
I=1;
strcpy(arr[0],line);
while(1)
{
gets(line);
if(!strcmp(line,"#")) break;
strcpy(arr[I],line);
I++;
}
compute(I);
printf("\n");
memset(res,0,sizeof(res));
memset(arr,0,sizeof(arr));
}
}