1. 程式人生 > >day3--UVA272 TEX Quotes

day3--UVA272 TEX Quotes

UVA272 TEX Quotes

題目翻譯

在TeX中,左雙引號的" `` “(1左邊的),右雙引號是” ‘’ "(回車左邊的).輸入一篇包含雙引號的文章,你的任務是把它轉換成TeX的格式。

題目描述

在這裡插入圖片描述

Input

Input will consist of several lines of text containing an even number of double-quote (") characters. Input is ended with an end-of-file character.

Output

The text must be output exactly as it was input except that: • the first " in each pair is replaced by two ` characters: `` and • the second " in each pair is replaced by two ’ characters: ‘’.

Sample Input

在這裡插入圖片描述

Sample Output

在這裡插入圖片描述

Java 程式碼實現

import java.util.Scanner;
public class TeX_quato {
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		boolean flag = true;
		while(sc.hasNextLine()){
			String str = sc.nextLine();
			char[] str_to_char =
str.toCharArray(); for(int i=0; i<str_to_char.length; i++ ){ if(str_to_char[i]=='"' && flag){ System.out.print("``"); flag = false; continue; } if(str_to_char[i]=='"' && flag==false){ System.out.print("''"); flag = true; continue; }
System.out.print(str_to_char[i]); } System.out.println(); } sc.close(); } }