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

猜你喜欢

转载自blog.csdn.net/sinat_41879565/article/details/82806566
TEX