这也是一道属于字符串方面的题目!
代码如下:
#include <iostream>
#include <cstring>
#include <cstdio>
using namespace std;
char a[201000];
int main()
{
int len,i,sum;
while((gets(a))!=NULL)
{
len=strlen(a);
sum=0;
for(i=0; i<len; i++)
{
string temp="";
temp=temp+a[i]+a[i+1];//这里蛮重要的,因为中文的“和”,不是单个字符,而是属于字符串!
if(temp=="“"||temp=="”")
{
sum++;
}
if(a[i]=='"')
{
if(sum%2==0)
printf("“");
else
printf("”");
sum++;
}
else if(a[i]==',')
printf(",");
else if(a[i]=='.')
printf("。");
else if(a[i]=='!')
printf("!");
else if(a[i]=='<'&&a[i+1]=='<')
{
printf("《");
i++;
}
else if(a[i]=='>'&&a[i+1]=='>')
{
printf("》");
i++;
}
else if(a[i]=='?')
printf("?");
else{printf("%c",a[i]);}
}
printf("\n");
}
return 0;
}