[Uva] Tex Quates (272)

UVA - 272

TEX Quotes

Time Limit: 3000MS   Memory Limit: Unknown   64bit IO Format: %lld & %llu

Submit Status

Description

TeX is a typesetting language developed by Donald Knuth. It takes source text together with a few typesetting instructions and produces, one hopes, a beautiful document. Beautiful documents use `` and " to delimit quotations, rather than the mundane " which is what is provided by most keyboards. Keyboards typically do not have an oriented double-quote, but they do have a left-single-quote ` and a right-single-quote . Check your keyboard now to locate the left-single-quote key ` (sometimes called the ``backquote key") and the right-single-quote key (sometimes called the ``apostrophe" or just ``quote"). Be careful not to confuse the left-single-quote ` with the ``backslash" key \. TeX lets the user type two left-single-quotes `` to create a left-double-quote `` and two right-single-quotes ‘‘ to create a right-double-quote ‘‘. Most typists, however, are accustomed to delimiting their quotations with the un-oriented double-quote ".

If the source contained

"To be or not to be," quoth the bard, "that is the question."

then the typeset document produced by TeX would not contain the desired form:

``To be or not to be," quoth the bard, ``that is the question."

In order to produce the desired form, the source file must contain the sequence:

``To be or not to be,‘‘ quoth the bard, ``that is the question.‘‘

You are to write a program which converts text containing double-quote (") characters into text that is identical except that double-quotes have been replaced by the two-character sequences required by TeX for delimiting quotations with oriented double-quotes. The double-quote (") characters should be replaced appropriately by either `` if the " opens a quotation and by ‘‘ if the " closes a quotation. Notice that the question of nested quotations does not arise: The first " must be replaced by ``, the next by ‘‘, the next by ``, the next by ‘‘, the next by``, the next by ‘‘, and so on.

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

"To be or not to be," quoth the Bard, "that
is the question".
The programming contestant replied: "I must disagree.
To `C‘ or not to `C‘, that is The Question!"

Sample Output

``To be or not to be,‘‘ quoth the Bard, ``that
is the question‘‘.
The programming contestant replied: ``I must disagree.
To `C‘ or not to `C‘, that is The Question!‘‘

地址:http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=19396

ac代码:

#include <cstdio>
using namespace std;
int main(){
	int c;
	bool flag = 1;
	while(scanf("%c", &c) != EOF)
		if (c == ‘"‘) {printf("%s", flag ? "``":"‘‘"); flag = !flag;}
		else printf("%c", c);
	return 0;
}

题目比代码长n倍典型范例 :)

时间: 2024-08-17 01:11:49

[Uva] Tex Quates (272)的相关文章

UVa 272 Tex Quotes --- 水题

题目大意:在TeX中,左引号是 ``,右引号是 ''.输入一篇包含双引号的文章,你的任务是把他转成TeX的格式 解题思路:水题,定义一个变量标记是左引号还是右引号即可 /* UVa 272 Tex Quotes --- 水题 */ #include <cstdio> #include <cstring> int main() { #ifdef _LOCAL freopen("D:\\input.txt", "r", stdin); #endi

TeX中的引号(TeX Quote, UVa 272)

(UVa代表弗吉尼亚大学,272是其OJ上的第272题) 在TeX中,左引号是""",右引号是""".输入一篇包含双引号的文章,你的任务是把它转换成TeX的格式. 样例输入; "To be or not to be,"quoth the Bard,"that is the question". 样例输出: "To be or not to be,"quoth the Bard,"

UVa 272——TeX Quotes

TeX Quotes Time limit: 3.000 seconds TeX is a typesetting language developed by Donald Knuth. It takes source text together with a few typesetting instructions and produces, one hopes, a beautiful document. Beautiful documents use `` and " to delimit

UVA 272 - TEX Quotes

题意:将给定字符串中的双引号改为规定格式,左右修改不同 分析:字符串中有空格,插入的引号必须用字符串表示,所有采用逐个字符串处理 注释:水题 1 //#define LOCAL 2 #include"iostream" 3 #include"cstdio" 4 using namespace std; 5 int main() 6 { 7 #ifdef LOCAL 8 freopen("input.txt","r",stdin

UVA 272 TEX Quotes 题解

//刚看刘汝佳的第二版紫书 1 #include <iostream> 2 #include <cstdio> 3 #include <cstring> 4 #include <cstdlib> 5 #include <cmath> 6 #include <algorithm> 7 #include <set> 8 #include <map> 9 #include <string> 10 #inc

TEX Quotes UVA - 272【字符串】

https://vjudge.net/problem/UVA-272 [分析]:标记一下. [代码]: #include <bits/stdc++.h> using namespace std ; int n,m; int main() { int f=1; char c; while(scanf("%c",&c) != EOF) { if(c == '"') { printf("%s",f ? "``":"

UVa 272

背景:今天写一道模拟题写了10个小时,仍然未果,故水此题借以开心. 思路:一个一个的读,遇到引号就交替着换为规定的引号. 学习: 1.这里特殊引号是一种特殊字符,并不是ASCII表那255个字符里具有的,所以只能把它当做字符串常量输出. 2.条件表达式的简约感. 3. <span style="font-size:18px;">(temp=getchar())!=EOF //括号不能省略.</span> 运算符优先级:关系运算符大于逻辑预算符大于复制运算符,逗号

272 TEX Quotes

#include<stdio.h>int main(){ char a; int b=1; while((a=getchar())!=EOF) { if(a=='"'&&b==1) { printf("``"); b=0; } else if(a=='"'&&b==0) { printf("''"); b=1; } if(a!='"') { printf("%c",a);

Uva 272 10082 401 字符串的读入 和 字符数组的初始化 很重要。

水题,但是唯一不好解决的就是题目的读入问题. 有一个方法是无论你怎么玩都可以通过的,空格回车什么的都可以被吃掉. //代码如下: while((c = getchar()){ ..... } 还知道了一个小小的实用函数:isalpha   判断是否为英文字母,如果是小写返回2,如果是大写返回1. 对于超级模拟的字符串等题来说,一个好的方法是在开头就建立关系,初始化很实用..嘿嘿. 三道水题,复习了一下字符的输入输出,想当年就因为这个,爆零的那叫一个惨啊.....