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

Ghaverves
New poster
Posts: 4
Joined: Mon Dec 13, 2010 2:49 pm

Re: 272 - TeX Quotes

Post by Ghaverves » Mon Dec 13, 2010 2:52 pm

Can anyone help with my code?
It's such a simple question and I keep getting wrong answer.
It is really frustrating.

Code: Select all

removed after AC
Last edited by Ghaverves on Thu Dec 16, 2010 2:29 pm, edited 1 time in total.

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

Re: 272 - TeX Quotes

Post by sohel » Wed Dec 15, 2010 2:04 pm

I think you are printing an additional character when you reach the end of file.
Try putting the input in a file and read if from there. You should be able to see the error.

Ghaverves
New poster
Posts: 4
Joined: Mon Dec 13, 2010 2:49 pm

Re: 272 - TeX Quotes

Post by Ghaverves » Thu Dec 16, 2010 2:28 pm

Thanks :)
you caught the error

MotherTiger
New poster
Posts: 2
Joined: Wed Mar 02, 2011 7:16 pm

272 Runtime Error?!

Post by MotherTiger » Wed Mar 02, 2011 7:19 pm

I got Runtime Error so many times, but don't know why!
Can anyone tell me what goes wrong please?
Thanks alot!

Code: Select all

#include <stdio.h>

int main()
{
	int counter = 0, flag = 0;
	char text[5000] = {0}, x;
	while((x = getchar()) != EOF)
	{
		if(x == '\"')
		{
			if(flag == 0)
			{
				text[counter] = '`';
				counter++;
				text[counter] = '`';
				flag = 1;
			}
			else
			{
				text[counter] = '\'';
				counter++;
				text[counter] = '\'';
				flag = 0;
			}
		}
		else
		{
			text[counter] = x;
		}
		counter++;
	}
	printf("%s", text);
	return 0;
}


fernandohbc
New poster
Posts: 5
Joined: Sat Aug 14, 2010 10:31 pm

Re: 272 Runtime Error?!

Post by fernandohbc » Thu Mar 03, 2011 5:07 am

I've just compiled and runned your code and turns out that it works fine in my box.
I even compared your output against my AC'd code's output and they are identical.
Have you searched for any additional input/output to test your code with?

MotherTiger
New poster
Posts: 2
Joined: Wed Mar 02, 2011 7:16 pm

Re: 272 Runtime Error?!

Post by MotherTiger » Thu Mar 03, 2011 8:55 am

fernandohbc wrote:I've just compiled and runned your code and turns out that it works fine in my box.
I even compared your output against my AC'd code's output and they are identical.
Have you searched for any additional input/output to test your code with?
Thanks for your reply!
Yes, i've tried some additional input/output and the code works fine.
That's wierd!

sadia_atique
New poster
Posts: 25
Joined: Thu Nov 24, 2011 6:32 am

Re: 272 - TeX Quotes

Post by sadia_atique » Fri Nov 25, 2011 5:28 pm

I have no idea why my code gets WA,please,can anyone kindly help me?? :(

Code: Select all

#include<stdio.h>
int main()
{
    char ch;
    int i=0;
    while(ch=getc(stdin)!=EOF)
    {
         if((int)ch==34)
         {
                        if (i==0)
                        {
                                 printf("``");
                                 i=1;
                        }
                        else if(i==1)
                        {
                             printf("''");
                             i=0;
                        }
         }
         else printf("%c",ch);
    }
    return 0;
}

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

Re: 272 - TeX Quotes

Post by sohel » Fri Nov 25, 2011 11:57 pm

The operators = and != have got the same precedence, however they are right associative.

That means ch = getc(stdin) != EOF is treated as ch = ( getc(stdin) != EOF ) and thus ch will always be assigned with a boolean (0/1) value.
You can get around this problem by enclosing the first two terms with parenthesis, something like ( ch = getc(stdin) ) != EOF

Hope it helps.

sadia_atique
New poster
Posts: 25
Joined: Thu Nov 24, 2011 6:32 am

Re: 272 - TeX Quotes

Post by sadia_atique » Sat Nov 26, 2011 5:52 am

Thanks a lot,it worked :D
How stupid mistake it was!!

kia.masster
New poster
Posts: 6
Joined: Thu Dec 22, 2011 8:47 am

Re: 272 - TeX Quotes

Post by kia.masster » Tue Jan 03, 2012 6:33 pm

Hi guys! What is the wrong of this code?

Code: Select all

#include <iostream>
#include <cstring>
#include <string>

using namespace std;

string s;

void Shift(int i){
	s += s[s.length() - 1];
	for (int j = s.length() - 2; j > i; j--)
		s[j + 1] = s[j];
}

int main(){
	while (getline(cin, s))
	{
		if (s.length() > 0)
		{
			int j = 0;
			int b = s.length();
			int z = 0;
			int ord = 39;
			for (int i = 0; i < b; i++)
			{
				int a = s[i + z];
				if (a == 34)
				{
					j++;
					if (j % 2 == 1)
					{
						s[i + z] = '`';
						Shift(i + z);
						s[i + z + 1] = '`';
						z++;
					}
					else
					{
						s[i + z] = ord;
						Shift(i + z);
						s[i + z + 1] = ord;
						z++;
					}
				}
			}
			cout << s << endl;
		}
	}
}

brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: 272 - TeX Quotes

Post by brianfry713 » Fri Jan 06, 2012 11:03 pm

kia.masster I can see you already figured out that you weren't closing the quotes correctly across multiple lines.
Check input and AC output for thousands of problems on uDebug!

islamzee
New poster
Posts: 2
Joined: Mon Apr 02, 2012 11:53 pm

Re: 272 - TeX Quotes

Post by islamzee » Sat Apr 28, 2012 10:13 pm

PLEASE HELP! getting crazy with WA all day long for this! i know there might be a shorter n easier way, bt what's specifically wrong with my code??

char str[1000000];

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

int main()
{
int i,j,count=0;

while(gets(str))
{
//count=0;

for(i=0;str;i++)
{
if(str!='"') printf("%c",str);

else
{
count=0;
j=i+1;
count++;

while(str[j])
{
if(str[j]=='"')
{
count++;
break;
}
j++;
}

if(count%2==0)
{
printf("``");
for(j=i+1;str[j]!='"';j++) printf("%c",str[j]);
printf("''");

i=j;
count=0;
}

else
{
if(str[i+1]==NULL) printf("''");
else printf("``");
}
}
}
printf("\n");

for(i=0;i<2000;i++) str=NULL;
}

return 0;
}

islamzee
New poster
Posts: 2
Joined: Mon Apr 02, 2012 11:53 pm

Re: 272 - TeX Quotes

Post by islamzee » Sat Apr 28, 2012 10:35 pm

one another thing...if input is [this"]
then would the last " be replaced by `` or ' ' ??

brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: 272 - TeX Quotes

Post by brianfry713 » Mon Apr 30, 2012 10:07 pm

Run your code and do a diff against the sample I/O. It doesn't match line 2.
Check input and AC output for thousands of problems on uDebug!

maruf.2hin
New poster
Posts: 1
Joined: Tue Jul 31, 2012 12:46 am

Re: 272 - TeX Quotes

Post by maruf.2hin » Wed Aug 01, 2012 10:43 pm

getting wrong answer....... for both code

Code: Select all

Accepted...............
and also for this.....

Code: Select all

 Accepteed...................

Post Reply

Return to “Volume 2 (200-299)”