题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1736
AC代码:
#include <cstdio>
#include <cstring>
#include <string>
#include <iostream>
using namespace std;
#define inf 999999
char a[inf];
int main(){
while(gets(a)){
int i,p=0;
int len=strlen(a);
for(i=0;i<len;i++){
string t="";
t=t+a[i]+a[i+1];
if(t=="“"||t=="”")
p=!p;
else if(t==">>"){
i++;
printf("》");
continue;
}
else if(t=="<<"){
i++;
printf("《");
continue;
}
/*
char t[2];
t[0]=a[i];
t[1]=a[i+1];
if(!strcmp(t, "“") || !strcmp(t, "”"))
p=!p;
else if(!strcmp(t,">>")){
i++;
printf("》");
continue;
}
else if(!strcmp(t,"<<")){
i++;
printf("《");
continue;
}
*/
if(a[i]=='"'){
if(p)
printf("”");
else
printf("“");
p=!p;
}
else if(a[i]==',')
printf(",");
else if(a[i]=='.')
printf("。");
else if(a[i]=='?')
printf("?");
else if(a[i]=='!')
printf("!");
else
printf("%c",a[i]);
}
printf("\n");
}
return 0;
}