Page 3 of 4

why tle????pls help me

Posted: Tue Jan 06, 2009 11:04 am
by tajbir2000
got AC

Re: 11220 - Decoding the message

Posted: Sat Jan 17, 2009 12:10 pm
by Obaida
To tajbir2000
You can never avoid TLE with this. You had to red input character by character and process them. :D

Why my one got TLE. I was getting wa in .04scc but when i was trying to change my output style. It got TLE.
Some one please check this. :(

Code: Select all

removed

Re: 11220 - Decoding the message

Posted: Sun Jan 18, 2009 1:46 pm
by vahid sanei
for output :
You must print a blank line between each test case.

Re: 11220 - Decoding the message

Posted: Mon Jan 19, 2009 7:32 am
by Obaida
I edited. But why this is TLE?????? :-?

Re: 11220 - Decoding the message

Posted: Sat Apr 18, 2009 8:25 am
by Obaida
Is there any wrong in taking input???
Why i got TLE? :-?
Some 1 plz help me.

Code: Select all

#include<stdio.h>
#include<string.h>
#include<ctype.h>
int main()
{
	int n,count=0,c,t_c,i,ca=0;
	bool print=0;
	char st[31];
	scanf("%d%*c",&n);
	scanf("%*c");
	while(1)
	{
		printf("Case #%d:\n",++ca);
		while(1)
		{
			gets(st);
			if(st[0]=='\0'){count++;break;}
			c=0;t_c=0;print=0;
			for(i=0;st[i];i++)
			{
				if(isspace(st[i]))
				{
					if(print){c++;print=0;}
					t_c=0;
				}
				else
				{
					if(t_c==c){printf("%c",st[i]);print=1;}
					t_c++;
				}
			}
			puts("");
		}
		if(count==n)break;
		puts("");
	}
	return 0;
}

Re: 11220 - Decoding the message

Posted: Tue Apr 21, 2009 4:15 pm
by MRH
hello " Obaida "
just add memset(st, 0, sizeof(st)); after puts("");
and netx time when u get this tyep problem then u use all of cin>> and cot<< .
OR use gets(str); for tast case then sscanf(str,"%d",&cas);

Re: 11220 - Decoding the message (Why WA)

Posted: Tue Sep 07, 2010 3:03 pm
by shaon_cse_cu08
Hello... with great afford's and after reading all the tread's.. I still can't figure out the BUG in my code.... I can realize I m printing extra newline or not printing 1 where it is need... But I cant find .... Plzzzz some 1 Help me... Here is my code... :( :(

Code: Select all

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

int main()
{
	int i,j,k,l,m,cas,t,tag,flag,len;

	char a[100][2000],bfr,b[100][500];

	scanf("%d",&t);

	printf("\n");

	scanf("%c",&bfr);

	for(cas=1;cas<=t;cas++)
	{

		for(i=0;;i++)
		{
			gets(a[i]);

			if(a[i][0]=='\0')
				break;
		}
		
		printf("Case #%d:\n",cas);

		for(j=0;j<i;j++)
		{
			l=0;
		    tag=1;
			flag=1;

			len=strlen(a[j]);
			for(k=0;k<len;k++)
			{
				if(tag&&a[j][k]!=' ')
					for(m=k+1;m<=k+l;m++)
						if(a[j][m]==' ')
						{
							flag=0;
							break;
						}

				if((m==k+l+1)&&flag&&m<len)
				{
					b[j][l]=a[j][k+l];

					tag=0;
					flag=0;
					l++;
				}
				if(a[j][k]==' ')
				{
					tag=1;
					flag=1;
				}
			}
			b[j][l]='\0';
			
			
			puts(b[j]);


		}
		if(cas<t)
			printf("\n");

	}
return 0;
}

Re: 11220 - Decoding the message

Posted: Sat Feb 05, 2011 8:53 pm
by kissu parina
dont print a new line after the last output...gave me a lot of pain :x

Re: 11220 - Decoding the message

Posted: Wed Nov 09, 2011 12:40 pm
by masum_cse
This is my code .I could'nt find out any reason ,why my code is getting WA....
Help ...me ..please>>>>>

#include<stdio.h>
#include<string.h>
int main()
{

int i,j,k,l,m,n;
char c[100000],ch;

scanf("%d",&n);
scanf("%c",&ch);
scanf("%c",&ch);
printf("Case #1:\n");

for(i=1;i<=n;i++)
{
k=0;
j=0;
m=0;

while(1)
{
scanf("%c",&ch);

if((ch>=65&&ch<=90)||(ch>=97&&ch<=122))
{
c[j++]=ch;
m=0;
}

else if(ch==' ')
{
if(k<j)
{
printf("%c",c[k]);
k++;
}
j=0;
m=0;
memset(c,'\0',sizeof(c));
}

else if(ch=='\n')
{
m++;
if(k<j)
{
printf("%c\n",c[k]);
k=0;
j=0;
memset(c,'\0',sizeof(c));
}
else if(m==2)
{
if(i==n)
break;
printf("Case #%d:\n",i+1);
m=0;
memset(c,'\0',sizeof(c));
break;
}

else
{
printf("\n");
j=0;
k=0;
memset(c,'\0',sizeof(c));
}
}

}

}
return 0;
}

Re: 11220 - Decoding the message

Posted: Mon Oct 07, 2013 11:25 pm
by shuvokr
xtranger991 try it

Code: Select all

scan test case
enter
enter
scan input and print output ( input is terminated when input is only a new line )
scan input and print output ( input is terminated when input is only a new line )
.......
.......

Re: 11220 - Decoding the message

Posted: Tue Oct 08, 2013 12:27 am
by shuvokr
@xtranger991 look this input and try it in your code, then you may be find why your code give the wrong answer
Sample input:

Code: Select all

2

Hey good lawyer
as I previously previewed
yam does a soup(and 4 space)    


Re: 11220 - Decoding the message

Posted: Fri Nov 22, 2013 6:48 pm
by Angry Bird
Getting WA for many times.... But why?

Code: Select all

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <vector>
#include <sstream>

using namespace std;

int counter;

void fn(string s)
{
    int l=s.size();

    if(l>=counter+1)
    {
        cout<<s[counter];
        counter++;
    }
}

int main()
{
    string s,smain;
    char ch;
    int t;
    cin>>t;
    getchar();
    for(int i=1; i<=t; i++)
    {
        vector<string>ss;
        scanf("\n");
        scanf("\n");
        while(getline(cin,smain))
        {
            if(smain=="")
            {
                break;
            }

            ss.push_back(smain);
        }

        cout<<"Case #"<<i<<":"<<endl;

        for(int j=0; j<ss.size(); j++)
        {
            counter=0;
            s=ss[j];
            vector<string>stor;
            istringstream iss(s);

            do
            {
                string sub;
                iss >> sub;
                stor.push_back(sub);
            }
            while (iss);

            for(int k=0; k<stor.size(); k++)
            {
                fn(stor[k]);
            }
            cout<<endl;
        }
        cout<<endl;
    }

    return 0;
}


Re: 11220 - Decoding the message

Posted: Fri Nov 22, 2013 9:53 pm
by brianfry713
You must print a blank line between each test case.

Don't print an extra blank line at the end.

Re: 11220 - Decoding the message

Posted: Fri Nov 22, 2013 10:58 pm
by Angry Bird
Thank you. AC

Re: 11220 - Decoding the message

Posted: Tue Jan 07, 2014 1:17 pm
by Shihab
WA help

Code: Select all

#include<stdio.h>
#include<string.h>
int main()
{
    int i=1,j,n,words,test_case,length,letters,characters;
    char text[110][40];
    FILE *fp,*op;
    //fp=fopen("Input.txt","r");
    //fscanf(fp,"%d",&test_case);
    scanf("%d",&test_case);
    while(i<=test_case)
    {
        j=0;
        printf("Case #%d:\n",i);
        while(gets(text[j]))
        {
            length=strlen(text[j]);
            if(length==0 && j>1)
                break;
            letters=words=1;
            characters=0;

            while(text[j][characters]!='\0')
            {
                if(text[j][characters]!=' ')//checking for words
                {
                    if(letters==1)
                        words++;

                    letters++;//counting letters in a word

                    if(letters==words)
                    {
                        printf("%c",text[j][characters]);
                    }
                }
                else
                {
                    if(letters<words && letters>1)
                        words--;

                    letters=1;
                }
                characters++;
            }
            j++;
            printf("\n");
        }
        //fclose(fp);
        i++;
    }
    return 0;
}