寒假练习——TEX Quotes
程序员文章站
2022-06-09 19:13:09
...
样例:
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;
}
上一篇: js常见的面试题算法
下一篇: 非正交多址技术NOMA基础知识