Page 7 of 10
Re: 272 - TeX Quotes
Posted: Mon Dec 13, 2010 2:52 pm
by Ghaverves
Can anyone help with my code?
It's such a simple question and I keep getting wrong answer.
It is really frustrating.
Re: 272 - TeX Quotes
Posted: Wed Dec 15, 2010 2:04 pm
by sohel
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.
Re: 272 - TeX Quotes
Posted: Thu Dec 16, 2010 2:28 pm
by Ghaverves
Thanks

you caught the error
272 Runtime Error?!
Posted: Wed Mar 02, 2011 7:19 pm
by MotherTiger
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;
}
Re: 272 Runtime Error?!
Posted: Thu Mar 03, 2011 5:07 am
by fernandohbc
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?
Re: 272 Runtime Error?!
Posted: Thu Mar 03, 2011 8:55 am
by MotherTiger
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!
Re: 272 - TeX Quotes
Posted: Fri Nov 25, 2011 5:28 pm
by sadia_atique
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;
}
Re: 272 - TeX Quotes
Posted: Fri Nov 25, 2011 11:57 pm
by sohel
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.
Re: 272 - TeX Quotes
Posted: Sat Nov 26, 2011 5:52 am
by sadia_atique
Thanks a lot,it worked
How stupid mistake it was!!
Re: 272 - TeX Quotes
Posted: Tue Jan 03, 2012 6:33 pm
by kia.masster
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;
}
}
}
Re: 272 - TeX Quotes
Posted: Fri Jan 06, 2012 11:03 pm
by brianfry713
kia.masster I can see you already figured out that you weren't closing the quotes correctly across multiple lines.
Re: 272 - TeX Quotes
Posted: Sat Apr 28, 2012 10:13 pm
by islamzee
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;
}
Re: 272 - TeX Quotes
Posted: Sat Apr 28, 2012 10:35 pm
by islamzee
one another thing...if input is [this"]
then would the last " be replaced by `` or ' ' ??
Re: 272 - TeX Quotes
Posted: Mon Apr 30, 2012 10:07 pm
by brianfry713
Run your code and do a diff against the sample I/O. It doesn't match line 2.
Re: 272 - TeX Quotes
Posted: Wed Aug 01, 2012 10:43 pm
by maruf.2hin
getting wrong answer....... for both code
and also for this.....