Page 6 of 10

Re: 272 -WA-Plz help to debug it!!!

Posted: Wed Dec 17, 2008 8:31 pm
by sazzadcsedu
thanx to dreadlord.

infact it was a stupid mistake.
i found it just after sending the problem to board.

however,thanx to dreadlord .

Re: 272 -WA-Plz help to debug it!!!

Posted: Wed Dec 17, 2008 9:59 pm
by dreadlord
sazzadcsedu wrote:thanx to dreadlord.

infact it was a stupid mistake.
[...]
You're welcome.

Sometimes, the most stupid mistakes are the ones that make us to waste more time (that's my own experience).

Now it's time to try a new problem :wink:

--Dread

Re: 272 -WA-Plz help to debug it!!!

Posted: Fri Jul 24, 2009 1:30 pm
by Jordi Aranda
What's wrong with my solution? I've tried many cases. Thx in advance

Code: Select all

Removed after accepted

Re: 272 -WA-Plz help to debug it!!!

Posted: Sat Jul 25, 2009 5:07 pm
by mf
Looks fine to me.

If that gets WA, then maybe the input is not a regular text file (i.e. it might have some funny characters, and miss \n at the end of file), and so you're supposed to read it character-by-character instead of line-by-line. Use getchar() function.

Re: 272 -WA-Plz help to debug it!!!

Posted: Sun Jul 26, 2009 12:14 am
by Jordi Aranda
mf wrote:Looks fine to me.

If that gets WA, then maybe the input is not a regular text file (i.e. it might have some funny characters, and miss \n at the end of file), and so you're supposed to read it character-by-character instead of line-by-line. Use getchar() function.
It's curious, I've just sent the same code now and it was accepted =S Thanks mf

272:Runtime error

Posted: Fri Dec 25, 2009 12:11 pm
by aaa111
Why i am getting runtime errror:

Code: Select all

#include<stdio.h>

int main()
{
char ch,line[10000];
int i,q_flag;


q_flag=0;
i=0;

while((ch=getchar())!=EOF)
	{
	line[i]=ch;
	i++;
	}

line[i]='\0';

for(i=0;line[i]!='\0';i++)
	{

	if((line[i]=='"')&&(q_flag==0))
		{
		q_flag=1;
		printf("``");
		}
	if(q_flag==1){
		      i++;
		      while(line[i]!='"' || line[i]!='\0')
			{
			if(line[i]=='"' || line[i]=='\0')
				break;
			printf("%c",line[i]);
			i++;
			}
		      if(line[i]!='\0')
			      printf("''");
		      q_flag=0;
		      }

		if(line[i]!='"'&&q_flag==0)
			printf("%c",line[i]);

	}


return 0;
}

Re: 272 - TeX Quotes

Posted: Mon Jul 05, 2010 2:39 pm
by sachin_midha
Hi, I must say that its hard to get AC here at UVA, I've got WA on numerou occasions only because of using int for unsigned int or whatever :x ...and now I have once again failed to get clear a very easy question...can plz someone help me find the error in my code?? :(
NOTE: The last getchar() was placed here by mistake & code has been edited.

Code: Select all

#include<stdio.h>
char ch[10000000];
int main()
{
    int i=0,flag=0;   
    char a;
    while((ch[i++]=getchar())!=EOF){
          a=ch[i-1];
          if(a=='"'){
                   if(!flag){
                             ch[i-1]='`';
                             ch[i]='`';
                             flag=1;
                   }
                   else{
                        ch[i-1]=39;
                        ch[i]=39;
                        flag=0;
                   }
                   i++;
          }
    }
    printf("%s\n",ch);
    return 0;
}

Re: 272 - TeX Quotes

Posted: Sat Jul 31, 2010 9:00 pm
by zobayer
sachin_midha wrote:Hi, I must say that its hard to get AC here at UVA, I've got WA on numerou occasions only because of using int for unsigned int or whatever :x ...and now I have once again failed to get clear a very easy question...can plz someone help me find the error in my code?? :(
Can you xplain what is the job of last getchar()... and, also, check for whitespaces randomly within the text.

Re: 272 - TeX Quotes

Posted: Fri Aug 13, 2010 11:56 am
by dewsworld
Simple thing shuld be kept smple :)

Code: Select all

//perhaps ACed solution is not allowed here 
}

Re: 272 - TeX Quotes

Posted: Sun Oct 31, 2010 1:42 am
by crystaltanvir
I GOT TLE... What's the problem???

Code: Select all

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

int main()
{
    while(1)
    {
        char get[500 + 5];
        gets(get);
        int j, c = 0, l;
        l = strlen(get);
        for(j = 0; j < l; j++)
        {
            if(get[j] == '\"')
            {
                c++;
                if(c % 2 != 0)
                {
                    int k;
                    k = l - 1;
                    while(k >= j + 1)
                    {
                        get[k + 1] = get[k];
                        k--;
                    }
                    get[j + 1] = '`';
                    get[j] = '`';
                }
                else
                {
                    int k;
                    k = l - 1;
                    while(k >= j + 1)
                    {
                        get[k + 1] = get[k];
                        k--;
                    }
                    get[j + 1] = '\'';
                    get[j] = '\'';
                }
                l++;
            }
            get[l] = '\0';
        }
        puts(get);
    }
}


Re: 272 - TeX Quotes

Posted: Sun Oct 31, 2010 10:12 am
by sohel
When does your program terminate?

Re: 272 - TeX Quotes

Posted: Mon Nov 01, 2010 3:11 am
by crystaltanvir
while(1) is the problem?????
should i use while(gets(get))????

Re: 272 - TeX Quotes

Posted: Mon Nov 01, 2010 6:24 am
by sohel
yes

Re: 272 - TeX Quotes

Posted: Wed Nov 03, 2010 1:49 pm
by crystaltanvir
same result

Re: 272 - TeX Quotes

Posted: Wed Nov 10, 2010 11:45 pm
by zobayer
Problem for kids should be thought of like kids.
But you are making it complex. Why do you need those nested loops?