寒假练习——TEX Quotes

样例:

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!''

题目大意:就是把输入中奇数次出现的 " 替换为 `` ,偶数次出现的 " 替换为 ''(从1开始计数)。注意输入整篇文章为一个整体,不需要换行重新计算引号,开始栽在这里,一直WA

AC代码:

#include<bits/stdc++.h>
int main()
{
    char s;
    int cnt=0;
    while(~scanf("%c",&s))
    {
        if(s=='\"'&&cnt%2==0)
        {
            printf("\``");
            cnt++;
        }
        else if(s=='\"'&&cnt%2!=0)
        {
            printf("\''");
            cnt++;
        }
        else if(s!='\"')
            printf("%c",s);
    }
    return 0;
}
发布了26 篇原创文章 · 获赞 1 · 访问量 428

猜你喜欢

转载自blog.csdn.net/qq_45309822/article/details/103993655