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 » Wed Dec 17, 2008 8:31 pm

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 » Wed Dec 17, 2008 9:59 pm

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

User avatar
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 » Fri Jul 24, 2009 1:30 pm

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 » Sat Jul 25, 2009 5:07 pm

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.

User avatar
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 » Sun Jul 26, 2009 12:14 am

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 » Fri Dec 25, 2009 12:11 pm

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 » Mon Jul 05, 2010 2:39 pm

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 » Sat Jul 31, 2010 9:00 pm

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 » Fri Aug 13, 2010 11:56 am

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 » Sun Oct 31, 2010 1:42 am

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

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

Re: 272 - TeX Quotes

Post by sohel » Sun Oct 31, 2010 10:12 am

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 » Mon Nov 01, 2010 3:11 am

while(1) is the problem?????
should i use while(gets(get))????
TANVIR

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

Re: 272 - TeX Quotes

Post by sohel » Mon Nov 01, 2010 6:24 am

yes

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

Re: 272 - TeX Quotes

Post by crystaltanvir » Wed Nov 03, 2010 1:49 pm

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 » Wed Nov 10, 2010 11:45 pm

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)”