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

ashfaqur.rahman
New poster
Posts: 2
Joined: Fri Jun 14, 2013 8:50 am

272 - TEX Quotes (WA)

Post by ashfaqur.rahman » Fri Jun 14, 2013 9:10 am

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

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

Re: 272 - TEX Quotes (WA)

Post by brianfry713 » Fri Jun 14, 2013 8:40 pm

Doesn't match the sample I/O.
Check input and AC output for thousands of problems on uDebug!

ashfaqur.rahman
New poster
Posts: 2
Joined: Fri Jun 14, 2013 8:50 am

Re: 272 - TEX Quotes (WA)

Post by ashfaqur.rahman » Fri Jun 14, 2013 11:42 pm

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

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

Re: 272 - TEX Quotes (WA)

Post by brianfry713 » Mon Jun 17, 2013 11:25 pm

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!``
Check input and AC output for thousands of problems on uDebug!

f.maru
New poster
Posts: 13
Joined: Wed Jul 31, 2013 2:27 pm

Re: 272 - TEX Quotes (WA)

Post by f.maru » Wed Jul 31, 2013 2:38 pm

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

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

Re: 272 - TEX Quotes (WA)

Post by brianfry713 » Thu Aug 01, 2013 12:25 am

Try reading a char at a time instead of line by line.
Check input and AC output for thousands of problems on uDebug!

pop7983
New poster
Posts: 2
Joined: Tue Apr 23, 2013 7:40 pm

272 - TEX Quotes plz help me , WA

Post by pop7983 » Wed Aug 21, 2013 11:35 pm

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

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

Re: 272 - TEX Quotes plz help me , WA

Post by brianfry713 » Thu Aug 22, 2013 10:58 pm

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.
Check input and AC output for thousands of problems on uDebug!

amberdp
New poster
Posts: 1
Joined: Thu Oct 10, 2013 2:28 pm

Re: 272 - TEX Quotes (WA)

Post by amberdp » Thu Oct 10, 2013 2:32 pm

Take the time to read through them.

Rika71
New poster
Posts: 11
Joined: Sat Apr 26, 2014 9:42 pm

Re: 272 - TEX Quotes (WA)

Post by Rika71 » Fri May 09, 2014 4:44 pm

getting WA.please help.Thank You

Code: Select all

removed
Last edited by Rika71 on Fri May 09, 2014 8:16 pm, edited 1 time in total.

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

Re: 272 - TEX Quotes (WA)

Post by brianfry713 » Fri May 09, 2014 8:00 pm

Run your code on the sample input. Check for ' and `
Check input and AC output for thousands of problems on uDebug!

Rika71
New poster
Posts: 11
Joined: Sat Apr 26, 2014 9:42 pm

Re: 272 - TEX Quotes (WA)

Post by Rika71 » Fri May 09, 2014 8:20 pm

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 :oops:

Blief.S
New poster
Posts: 16
Joined: Wed Jun 18, 2014 9:03 pm

Got Presentation Error. Tried every way. still PE. Plz help

Post by Blief.S » Wed Jun 18, 2014 10:08 pm

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;

}

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

Re: Got Presentation Error. Tried every way. still PE. Plz h

Post by brianfry713 » Thu Jun 19, 2014 10:22 pm

What's the problem number?
Check input and AC output for thousands of problems on uDebug!

Blief.S
New poster
Posts: 16
Joined: Wed Jun 18, 2014 9:03 pm

Re: Got Presentation Error. Tried every way. still PE. Plz h

Post by Blief.S » Thu Jun 19, 2014 10:58 pm

text quotes - 272

Post Reply

Return to “Volume 2 (200-299)”