首页 > 其他分享 >例题3-1 TeX中的引号(Tex Quotes, UVa 272)

例题3-1 TeX中的引号(Tex Quotes, UVa 272)

时间:2023-04-01 16:33:56浏览次数:53  
标签:TeX EOF 双引号 Tex flag printf 例题

题目

在TeX中,左双引号是“``”,右双引号是“''”。输入一篇包含双引号的文章,
你的任务是把它转换成TeX的格式。

样例输入

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

样例输出

``To be or not to be,'' quoth the Bard, ``that
is the question''.

思路

依次读入字符, flag表示左右

代码


#include <iostream>
#include <cstdio>

using namespace std;

int main()
{
//    freopen("output.txt","w",stdout);
    char c;
    bool flag = true;
    while((c = getchar()) != EOF)
    {
        if(c == '"')
        {
            printf("%s",flag ? "``" : "''");
            flag = !flag;
        }
        else printf("%c",c);
    }
    return 0;
}

错误点

while(c = getchar() != EOF)

标签:TeX,EOF,双引号,Tex,flag,printf,例题
From: https://www.cnblogs.com/isYu/p/17278823.html

相关文章