day3--UVA272 TEX Quotes
阿新 • • 發佈:2018-12-11
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();
}
}