算法 干货!!!TeX括号 打卡第一天

【题目】在TeX中,左双引号是”,右双引号是“。输入一篇包含双引号的文章,你的任务是把他转换成TeX的格式。

【样例输入】

"To be or not to be,"quoth the Bard,“that is quesion”.

【样例输出】

”To be or not to be, ”quoth the Bard,“ that isquesion ”.
【分析】
本题的关键是,如何判断一个引号是是左双引号还是右双引号
使用一个标志变量即可。

#include<stdio.h>
int main()
{
    int c,q=1;
    while((c=getchar())!=EOF)
    {
        if(c=='"')
        {
            printf("%s",q?"“":"”");
            q=!q;
        }
        else
            printf("%c",c);
    }
    return 0;
}

#include <iostream>
#include <cstdio>
using namespace std;
int main()
{
    int c,q=1;
    while((c=getchar())!=0)
    {
        if (c=='"')
        {
            if (q==1)
            {
                cout<<"“";
                q=!q;
            }
            else
            {
                cout<<"”";
                q=!q;
            }
        }
        else
        {
            putchar(c);
        }
    }
    return 0;
}

不要觉得简单就可以忽略,难题都是由简单的组合而成,其实他之所以难,只是比较综合罢了!!!奥里给!!!

发布了8 篇原创文章 · 获赞 8 · 访问量 1787

猜你喜欢

转载自blog.csdn.net/qq_45748475/article/details/104193837