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

natanpedrosa
New poster
Posts: 1
Joined: Tue Sep 22, 2015 1:21 am

Re: 272 - TEX Quotes

Post by natanpedrosa » Tue Sep 22, 2015 1:48 am

Hi guys, I don't have any idea why my code is getting wa on this problem. Can anyone help me pls.

Code: Select all

import static java.lang.System.in;

import java.util.Scanner;

public class Main {

	// 272 - TEX Quotes
	
	public static void main(String[] args) {
		Scanner read = new Scanner(in);
		String line, text = "", output = "";
		boolean open = true, close = false;
		int length;
		while(read.hasNextLine()){
			line = read.nextLine();
			
			length = line.length();
			
			for(int i = 0; i < length && i != -1; i++){
					
				if(line.indexOf("\"") != -1 && open){
					line = line.replaceFirst("\"","``");
					open = false;
					close = true;
										
				}
				
				if(line.indexOf("\"") != -1 && close){
					line = line.replaceFirst("\"","''");
					open = true;
					close = false;										
				}
				
				i = line.indexOf("\"") - 1;
								
			}
			
			output = output + line +"\n";
			
		}
		
		System.out.println(output);
	}
}


manikyousuf
New poster
Posts: 1
Joined: Sat Dec 12, 2015 4:26 am

Re: 272 - TEX Quotes

Post by manikyousuf » Sat Dec 12, 2015 4:31 am

#include <stdio.h>
#include <string.h>
int main()
{
char ara[1000000];

while (gets(ara) != 0){

int len, i, x=0;

len = strlen(ara);

for (i=0; i<len; i++) {

if (x == 0) {
if (ara == '"') {
printf("``");
x = 1;
}
else {
printf("%c", ara);
}
}
else {
if (ara == '"') {
printf("''");
x = 0;
}
else {
printf("%c", ara);
}
}
}
printf("\n");
}
return 0;
}
Here is my code and i get WA in many times but why i don't know. Please help me to get AC

Post Reply

Return to “Volume 2 (200-299)”