272 - TEX Quotes

All about problems in Volume 2. If there is a thread about your problem, please use it. If not, create one with its number in the subject.

Moderator: Board moderators

Post Reply
sazzadcsedu
Experienced poster
Posts: 136
Joined: Sat Nov 29, 2008 8:01 am
Location: narayangong,bangladesh.
Contact:

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

Post 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 .
Life is more complicated than algorithm.
http://felix-halim.net/uva/hunting.php?id=32359
For Hints: http://salimsazzad.wordpress.com
dreadlord
New poster
Posts: 19
Joined: Sat Apr 19, 2008 11:19 pm

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

Post 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
Jordi Aranda
New poster
Posts: 13
Joined: Wed Apr 29, 2009 11:37 am
Location: Barcelona

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

Post by Jordi Aranda »

What's wrong with my solution? I've tried many cases. Thx in advance

Code: Select all

Removed after accepted
Last edited by Jordi Aranda on Sun Jul 26, 2009 12:13 am, edited 1 time in total.
Born to be wild
mf
Guru
Posts: 1244
Joined: Mon Feb 28, 2005 4:51 am
Location: Zürich, Switzerland
Contact:

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

Post 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.
Jordi Aranda
New poster
Posts: 13
Joined: Wed Apr 29, 2009 11:37 am
Location: Barcelona

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

Post 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
Born to be wild
aaa111
New poster
Posts: 14
Joined: Sat Nov 21, 2009 2:55 pm

272:Runtime error

Post 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;
}
sachin_midha
New poster
Posts: 5
Joined: Sun Jun 27, 2010 2:26 pm

Re: 272 - TeX Quotes

Post 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;
}
Last edited by sachin_midha on Sun Aug 01, 2010 1:14 pm, edited 2 times in total.
Sachin
zobayer
Experienced poster
Posts: 110
Joined: Tue May 06, 2008 2:18 pm
Location: CSE-DU, Bangladesh
Contact:

Re: 272 - TeX Quotes

Post 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.
You should not always say what you know, but you should always know what you say.
dewsworld
New poster
Posts: 12
Joined: Fri Aug 13, 2010 11:52 am

Re: 272 - TeX Quotes

Post by dewsworld »

Simple thing shuld be kept smple :)

Code: Select all

//perhaps ACed solution is not allowed here 
}
crystaltanvir
New poster
Posts: 6
Joined: Mon Oct 18, 2010 8:13 pm
Location: Bangladesh

Re: 272 - TeX Quotes

Post 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);
    }
}

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

Re: 272 - TeX Quotes

Post by sohel »

When does your program terminate?
crystaltanvir
New poster
Posts: 6
Joined: Mon Oct 18, 2010 8:13 pm
Location: Bangladesh

Re: 272 - TeX Quotes

Post by crystaltanvir »

while(1) is the problem?????
should i use while(gets(get))????
TANVIR
sohel
Guru
Posts: 856
Joined: Thu Jan 30, 2003 5:50 am
Location: New York

Re: 272 - TeX Quotes

Post by sohel »

yes
crystaltanvir
New poster
Posts: 6
Joined: Mon Oct 18, 2010 8:13 pm
Location: Bangladesh

Re: 272 - TeX Quotes

Post by crystaltanvir »

same result
TANVIR
zobayer
Experienced poster
Posts: 110
Joined: Tue May 06, 2008 2:18 pm
Location: CSE-DU, Bangladesh
Contact:

Re: 272 - TeX Quotes

Post by zobayer »

Problem for kids should be thought of like kids.
But you are making it complex. Why do you need those nested loops?
You should not always say what you know, but you should always know what you say.
Post Reply

Return to “Volume 2 (200-299)”