库函数的使用:POJ1488-TEX Quotes(getline()的使用)
TEX Quotes
Time Limit: 1000MS
Memory Limit: 10000K
Total Submissions: 9385
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 double-left-quote and double-right-quote 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 toC’, 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!”
解题心得:
- 题意就是让你将字符串中的英文的双引号改成类似于中文的双引号(并不是中文双引号),很简单,但是要注意一点就是双引号是具有方向的。
- 然后就是读入问题,其实可以使用getline来对string类型的进行读入,getline可以读入空格,在遇到回车的时候停止读入,很好用的,读入的格式如下
#include<string>//这个是getline 的头文件
string str;
getline(cin,str);
代码:
#include<bits/stdc++.h>
using namespace std;
const int maxn = 1e5;
string s;
int main()
{
bool flag = false;
//用来进行左右双引号的区分
while(getline(cin,s))
{
int len = s.length();
for(int i=0;i<len;i++)
{
if(s[i] == '"')
{
if(!flag)
printf("``");
else
printf("''");
flag = !flag;
}
else
printf("%c",s[i]);
}
printf("\n");
}
return 0;
}
库函数的使用:POJ1488-TEX Quotes(getline()的使用)的更多相关文章
- Uva272.TEX Quotes
题目链接:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...
- UVa 272 Tex Quotes --- 水题
题目大意:在TeX中,左引号是 ``,右引号是 ''.输入一篇包含双引号的文章,你的任务是把他转成TeX的格式 解题思路:水题,定义一个变量标记是左引号还是右引号即可 /* UVa 272 Tex Q ...
- POJ 1488 Tex Quotes --- 水题
POJ 1488 题目大意:给定一篇文章,将它的左引号转成 ``(1的左边),右引号转成 ''(两个 ' ) 解题思路:水题,设置一个bool变量标记是左引号还是右引号即可 /* POJ 1488 T ...
- UVA 272 TEX Quotes
TEX Quotes 题意: 变引号. 题解: 要想进步,真的要看一本好书,紫书P45 代码: #include<stdio.h> int main() { int c,q=1; whil ...
- TEX Quotes(字符串,水)
TEX Quotes Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 9674 Accepted: 5073 Descri ...
- 【UVA272】TEX Quotes
A - TEX Quotes Time Limit:3000MS Memory Limit:0KB 64bit IO Format:%lld & %llu Submitcid=80 ...
- Uva - Uva272 - TEX Quotes
TeX is a typesetting language developed by Donald Knuth. It takes source text together with a few ty ...
- POJ 1488 - TEX Quotes
Description TEX is a typesetting language developed by Donald Knuth. It takes source text together w ...
- uva 272 Tex中的引号(Tex Quotes)
TeX is a typesetting language developed by Donald Knuth. It takes source text together with a few ty ...
随机推荐
- Linux上常用命令整理(二)—— paste
上一篇整理了cat指令的几个基本常见用法,这次整理一下paste指令的基本用法. cat paste cut grep paste paste可以简单的理解为把两个文件的内容按列合并,与cat命令直接 ...
- 037 Sudoku Solver 解数独
写一个程序通过填充空格来解决数独.空格用 '.' 表示. 详见:https://leetcode.com/problems/sudoku-solver/description/ class Solut ...
- ES6:string.raw浅析
当前正学习ES6 ,遇到string.raw费心思,现将试验后的结果整理如下: 网上得来的试验: 语法 String.raw`templateStr`; String.raw(obj, ...subs ...
- ADC中的滤波算法
STM32的AD最大输入时钟不超过14MHZ,最高采样速度1us,可以采用DMA或者内部的基本定时器/高级定时器来触发,利用模拟看门狗监控所选择的的所有通道,如果超过模拟的 阀[fá] 值,将产生中断 ...
- Jenkins+Gitlab+Ansible自动化部署(四)
接Jenkins+Gitlab+Ansible自动化部署(三)https://www.cnblogs.com/zd520pyx1314/p/10235394.html Jenkins应用 Jenkin ...
- Swing---WindowConstants
Java桌面开发过程中,很多人都写过类似下面的代码. import javax.swing.JFrame; public class SimpleFrame { public static void ...
- 【虚拟机-部署】通过 Powershell 来调整 ARM 模式下虚拟机的尺寸
需求描述 在部署完 ARM 模式的虚拟机以后,可以通过 PowerShell 命令来调整虚拟机的尺寸,以下是通过 PowerShell 命令来调整 ARM 模式的虚拟机尺寸. Note 本文只限于 A ...
- java面试题(杨晓峰)---第七讲谈谈int和integer有什么区别?
理解装箱和拆箱的过程. 对象由三部分组成:对象头,对象实例,对齐填充. 对象头:一般是十六个字节,分两部分,第一部分:哈希码,锁状态标志,线程持有的锁,偏向线程id,gc分代年龄等,第二部分是类型指针 ...
- EF6.0注意事项
EF6 1.必须要添加Entitiframework 2.必须要添加必须要添加Entitiframework.Sqlserver 3.单元测试一定要有配置文件里面一定要有连接字符串和初始化配置文件节点 ...
- UVA 1606 Amphiphilic Carbon Molecules 两亲性分子 (极角排序或叉积,扫描法)
任意线可以贪心移动到两点上.直接枚举O(n^3),会TLE. 所以采取扫描法,选基准点,然后根据极角或者两两做叉积比较进行排排序,然后扫一遍就好了.旋转的时候在O(1)时间推出下一种情况,总复杂度为O ...