http://poj.org/problem?id=1488
曾经做过一个类似的,也是对双引号进行修改。
这题要使用整行读人,我习惯使用gets()函数,当然也有其他的函数get(cin,string s)、cin.getline(charArray, max_length,’\n’)。但有时做字符串题时会发生与换行符有关的错误,不能理解!
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!''
Source Code
#include <stdio.h>
#include <string.h>
const int N = 1000;
int main(){
int i,j,cnt=0;
char src[N],dst[N];
while(gets(src)){
for(i=j=0;i<strlen(src);i++){
if(src[i]!='"'){
dst[j++]=src[i];
}
else {
cnt=(cnt+1)%2;
if(cnt){
dst[j++]='`';
dst[j++]='`';
}
else{
dst[j++]='\'';
dst[j++]='\'';
}
}
}
dst[j]='\0';
printf("%s\n",dst);
}
return 0;
}
转载于:https://www.cnblogs.com/pcwl/archive/2011/04/26/2029717.html
发布者:全栈程序员-用户IM,转载请注明出处:https://javaforall.cn/100837.html原文链接:https://javaforall.cn
【正版授权,激活自己账号】: Jetbrains全家桶Ide使用,1年售后保障,每天仅需1毛
【官方授权 正版激活】: 官方授权 正版激活 支持Jetbrains家族下所有IDE 使用个人JB账号...