POJ 1488: TEX Quotes 题解
来源:互联网 发布:知乎英文名 编辑:程序博客网 时间:2024/05/29 13:09
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, "thatis 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, ``thatis the question''.The programming contestant replied: ``I must disagree.To `C' or not to `C', that is The Question!''
简述:
输入一串字符,要把字符中的 " 改掉,第一次出现的 " 改为``,第二次出现的 " 改为 ’’,依此类推。
思路:
因为要把一个字符改为两个字符,所以用getchar一个一个读入输出,因为要判断是改为哪一种引号,所以我选择加一个flag来判断。
一开始我让flag++,求余判断用哪一个引号,但这样提交结果wrong answer,因为flag会溢出,后来改为直接判断一次赋值一次就AC了。
下面是实现代码:
#include <stdio.h>int main(){ char c,flag = 0; while( (c = getchar()) != EOF) { if (c == '"' && flag == 0) { printf("``"); flag = 1; } else if (c == '"' && flag == 1) { printf("''"); flag = 0; } else { printf("%c",c); } } return 0;}
- POJ 1488: TEX Quotes 题解
- POJ 1488 TEX Quotes
- [POJ]1488 TEX Quotes
- POJ 1488 TEX Quotes
- poj 1488 TEX Quotes
- poj 1488 TEX Quotes
- POJ-1488TEX Quotes
- POJ 1488 TEX Quotes
- poj 1488 TEX Quotes
- POJ 1488 TEX Quotes
- POJ 1488 - TEX Quotes
- POJ - 1488 - TEX Quotes (字符串!)
- poj 1488 TEX Quotes 【水题】
- POJ 1488:TEX Quotes【字符串】
- POJ 1488 TEX Quotes 笔记
- Tex Quotes (P45) / POJ 1488
- poj 1488 TEX Quotes 字符串(水题)
- poj 1488 TEX Quotes(简单的串)
- 【asp.net】常用内置对象(Request,Response、server、Cookies)
- SGU131--NYOJ435
- hdu 4810 Wall Painting 位操作
- 【转】机器学习中导数最优化方法(基础篇)
- Spring AOP三种配置详细介绍
- POJ 1488: TEX Quotes 题解
- 1061. Dating (20)
- Failed reading value of registry key错误解决方法
- JUnit运行报错:ClassNotFoundException 解决办法
- R12.2 克隆系统结束后 autocfg 报错 rtld: 0712-001 Symbol __pth_init was referenced from module FNDCPUCF
- HttpPost 的使用
- Codeforces Round #304 (Div. 2) D. Soldier and Number Game 数论 筛表法
- BZOJ 1008 [HNOI2008] 越狱(简单组合数学)
- 黑马程序员——JavaIO流