欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

寒假练习——TEX Quotes

程序员文章站 2022-06-09 19:13:09
...

寒假练习——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;
}

 

相关标签: 题集