Page 8 of 10
272 - TEX Quotes (WA)
Posted: Fri Jun 14, 2013 9:10 am
by ashfaqur.rahman
Problem Link:
http://tinyurl.com/ll5js9p
I think my solution is right as its giving right output. But I am getting WA. Cant understand why!
Code: Select all
#include <stdio.h>
#include <string.h>
int main(){
//freopen("input", "r", stdin);
//freopen("output", "w", stdout);
char str[100], tmp1, tmp2;
int chk_qt, i, j, str_len;
while(gets(str)){
chk_qt = 0;
str_len = strlen(str);
for(i=0; i<str_len; i++){
if(str[i]=='"'){
if(chk_qt==0){
str_len++;
str[i] = '`';
tmp1 = str[i+1];
str[i+1] = '`';
for(j=i+2; j<str_len; j++){
tmp2 = str[j];
str[j] = tmp1;
tmp1 = tmp2;
}
chk_qt = 1;
}
else{
str_len++;
str[i] ='\'';
tmp1 = str[i+1];
str[i+1] = '\'';
for(j=i+2; j<str_len; j++){
tmp2 = str[j];
str[j] = tmp1;
tmp1 = tmp2;
}
chk_qt = 0;
}
}
}
str[str_len] = '\0';
printf("%s\n",str);
}
return 0;
}
Re: 272 - TEX Quotes (WA)
Posted: Fri Jun 14, 2013 8:40 pm
by brianfry713
Doesn't match the sample I/O.
Re: 272 - TEX Quotes (WA)
Posted: Fri Jun 14, 2013 11:42 pm
by ashfaqur.rahman
For Input:
"To be or not to be," quoth the Bard, "that is the question".
My Code Output:
``To be or not to be,'' quoth the Bard, ``that is the question''.
For Input:
The programming contestant replied: "I must disagree. To `C' or not to `C', that is The Question!"
My Code Output:
The programming contestant replied: ``I must disagree. To `C' or not to `C', that is The Question!''
Then Whats Wrong? @ brainfry713
Re: 272 - TEX Quotes (WA)
Posted: Mon Jun 17, 2013 11:25 pm
by brianfry713
Sample input:
Code: Select all
"To be or not to be," quoth the Bard, "that
is the question".
The programming contestant replied: "I must disagree.
To `C' or not to `C', that is The Question!"
Sample output:
Code: Select all
``To be or not to be,'' quoth the Bard, ``that
is the question''.
The programming contestant replied: ``I must disagree.
To `C' or not to `C', that is The Question!''
Your output:
Code: Select all
``To be or not to be,'' quoth the Bard, ``that
is the question``.
The programming contestant replied: ``I must disagree.
To `C' or not to `C', that is The Question!``
Re: 272 - TEX Quotes (WA)
Posted: Wed Jul 31, 2013 2:38 pm
by f.maru
Hi guys
i think my program is correct but i got WA
#include <iostream>
#include <string.h>
using namespace std;
int main()
{
string g,f;
int w=1;
while(getline(cin,g))
{
f.clear();
if(g.length()>0)
{
for(int i=0;i<=g.length();i++)
{
if (int(g)==34)
{
if(w%2==1)
f+="``";
if(w%2==0)
f+="''";
w++;
}
else
f+=g;
}
}
cout<<f<<endl;
}
return 0;
}
Re: 272 - TEX Quotes (WA)
Posted: Thu Aug 01, 2013 12:25 am
by brianfry713
Try reading a char at a time instead of line by line.
272 - TEX Quotes plz help me , WA
Posted: Wed Aug 21, 2013 11:35 pm
by pop7983
I have a little problem in my code , so I got WA
bellow is my code
Code: Select all
import java.util.Scanner;
public class Main
{
public static void main(String[] args)
{
String str;
boolean status = false;
Scanner scan = new Scanner(System.in);
while (scan.hasNextLine())
{
StringBuffer buf = new StringBuffer(scan.nextLine());
for (int i = 0; i < buf.length(); i++)
{
if (buf.charAt(i) == '\"' && status == false)
{ // false mean the first time the "
buf.deleteCharAt(i);
buf.insert(i, '`');
buf.insert(i, '`');
status = true;
}
else if (i + 1 < buf.length())
if (buf.charAt(i) == '`' && buf.charAt(i + 1) == '`' && status == false)
status = true; // false mean the first time the ``
else if (i + 1 < buf.length())
if (buf.charAt(i) == '\'' && buf.charAt(i + 1) == '\'' && status == false)
{
buf.deleteCharAt(i); // false mean the first time the ' '
buf.deleteCharAt(i);
buf.insert(i, '`');
buf.insert(i, '`');
status = true;
}
else if (buf.charAt(i) == '\"' && status == true)
{
buf.deleteCharAt(i); // true mean the second time the "
buf.insert(i, '\'');
buf.insert(i, '\'');
status = false;
}
else if (i + 1 < buf.length())
if (buf.charAt(i) == '`' && buf.charAt(i + 1) == '`' && status == true)
{
buf.deleteCharAt(i); // true mean the second time the ``
buf.deleteCharAt(i);
buf.insert(i, '\'');
buf.insert(i, '\'');
status = false;
}
else if (i + 1 < buf.length())
if (buf.charAt(i) == '\'' && buf.charAt(i + 1) == '\'' && status == true)
status = false; // true mean the second time the ' '
}
System.out.println(buf);
} // scan.close();
}
}
And I also have the other problem is when I input the sample input to my program.
the last line string I want press the enter i will display:(
Sample Output:
``To be or not to be,'' quoth the Bard, ``that
is the question''.
The programming contestant replied: ``I must disagree.
To `C' or not to `C', that is The Question!''
my Output:
``To be or not to be,'' quoth the Bard, ``that
is the question''.
The programming contestant replied: ``I must disagree. <-------------Is there I just press "Enter" to continue, then show the last line result. But I don't know why ,plz help me.
To `C' or not to `C', that is The Question!''
thx:)
Re: 272 - TEX Quotes plz help me , WA
Posted: Thu Aug 22, 2013 10:58 pm
by brianfry713
For the sample input, your output is:
Code: Select all
``To be or not to be,'' quoth the Bard, ``that
is the question''.
The programming contestant replied: ``I must disagree.
To `C' or not to `C', that is The Question!"
Correct output:
Code: Select all
``To be or not to be,'' quoth the Bard, ``that
is the question''.
The programming contestant replied: ``I must disagree.
To `C' or not to `C', that is The Question!''
You're not converting the " at the end of the last line.
Re: 272 - TEX Quotes (WA)
Posted: Thu Oct 10, 2013 2:32 pm
by amberdp
Take the time to read through them.
Re: 272 - TEX Quotes (WA)
Posted: Fri May 09, 2014 4:44 pm
by Rika71
getting WA.please help.Thank You
Re: 272 - TEX Quotes (WA)
Posted: Fri May 09, 2014 8:00 pm
by brianfry713
Run your code on the sample input. Check for ' and `
Re: 272 - TEX Quotes (WA)
Posted: Fri May 09, 2014 8:20 pm
by Rika71
brianfry713 wrote:Run your code on the sample input. Check for ' and `
Thanks GURU.I thought that all the separate lines were in a same line.how foolish

Got Presentation Error. Tried every way. still PE. Plz help
Posted: Wed Jun 18, 2014 10:08 pm
by Blief.S
Code: Select all
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int main()
{
char a='"',b='`',d;
char str[1000];
int i,c=0;
while(scanf("%s%c",&str,&d)!=EOF){
for(i=0;i<strlen(str);i++){
if (str[i]==a){
if(c==0) {
printf ("%c%c",b,b);
c++;
}
else {
printf("''");
c=0;
}
}
else printf("%c",str[i]);
}
printf(" ");
if (d=='\n') printf("\n");
}
return 0;
}
Re: Got Presentation Error. Tried every way. still PE. Plz h
Posted: Thu Jun 19, 2014 10:22 pm
by brianfry713
What's the problem number?
Re: Got Presentation Error. Tried every way. still PE. Plz h
Posted: Thu Jun 19, 2014 10:58 pm
by Blief.S
text quotes - 272