题目
Input
- Input will consist of several lines of text containing an even number
of double-quote (") characters. Input is ended with an end-of-file
character.
Output
- The text must be output exactly as it was input except that:
the first " in each pair is replaced by two ` characters: `` and
the second " in each pair is replaced by two ’ characters: ‘’.
题解
#define LOCAL
#include <cstdio>
using namespace std;
int main (){
int c,t = 1;
while ((c=getchar())!= EOF){
if (c == '"'){
printf("%s",t? "``":"''");t = !t;
}
else printf("%c",c);
}
return 0;
}
Tips
- 注意 getchar() 的输入是 int
- 简便写法 while ((c=getchar())!= EOF)
- 不用转义符 if (c == ‘"’)
- 可以将printf 提前, printf("%s",t? “``” : “’’”)
- t 虽然是 int,t = !t 也可以执行