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
marcelodata
New poster
Posts: 2
Joined: Mon May 30, 2016 2:03 am

272 - TEX Quotes

Post by marcelodata » Mon May 30, 2016 5:53 am

Hi, I have this JAVA code for 272 - TEX Quotes, I tried using UDebug and it's OK. , but when I submit my code it's WA. Why? Where is my mistake?

Code: Select all

import java.util.Scanner;
import static java.lang.System.out;

public class Main {

    public static void main(String[] args) {
        
        Scanner in = new Scanner(System.in);
        String linea, cad;
        int c;
        
        while (in.hasNext()) {
            linea = in.nextLine();
            cad = "";
            c = 1;
                        
            for (int i = 0; i < linea.length(); i++) {
                
                if (linea.substring(i,i + 1).compareTo("\"") == 0) {
                    if (c % 2 == 1) 
                        cad += "``";                        
                    else 
                        cad += "''";
                    
                    c++;
                }
                else {
                    cad += linea.substring(i, i + 1);
                }
                    
            }
            
            out.println(cad);
                
        }
        
    }
    
}

marcelodata
New poster
Posts: 2
Joined: Mon May 30, 2016 2:03 am

Re: 272 - TEX Quotes

Post by marcelodata » Tue May 31, 2016 7:28 pm

I got the mistake myself, there were two mistakes:

1. in.hasNext()
this reader of EOF didn't work for null strings, I had to improve in.hasNextLine().
2. The counter "c" wasn´t in the right place.

Anyway thank you for your help.

adarsh.5
New poster
Posts: 2
Joined: Fri Jun 03, 2016 8:50 pm

Re: 272 - TEX Quotes

Post by adarsh.5 » Fri Jun 03, 2016 9:03 pm

any one how to take input in a string in c++ for 272 problem
till EOF occurs?

adarsh.5
New poster
Posts: 2
Joined: Fri Jun 03, 2016 8:50 pm

Re: 272 - TEX Quotes

Post by adarsh.5 » Fri Jun 03, 2016 9:04 pm

plzz help anyone
thanks in advance

metaphysis
Experienced poster
Posts: 139
Joined: Wed May 18, 2011 3:04 pm

Re: 272 - TEX Quotes

Post by metaphysis » Thu Jun 09, 2016 2:24 pm

You can use code below to read input.

Code: Select all

cin.unsetf(ios::skipws);
char input;
while (cin >> input)
{
    ...    
}

Post Reply

Return to “Volume 2 (200-299)”