hdu1736
美观化文字
Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 2378 Accepted Submission(s): 493
Problem Description
请看下面两段文字:
Kenny喊道:"我来了!"
Kenny喊道:“我来了!”
前面一段文字中由于在中文中使用了英文标点,显得不太美观。本题中你的任务是让任意一段文字美观化。美观化具体要求为将以下字符(串)转换为对应的中文字符:
Kenny喊道:"我来了!"
Kenny喊道:“我来了!”
前面一段文字中由于在中文中使用了英文标点,显得不太美观。本题中你的任务是让任意一段文字美观化。美观化具体要求为将以下字符(串)转换为对应的中文字符:
英文 中文
, ,
. 。
! !
" “或”
<< 《
>> 》
? ?
Input
输入文字只有一段。文字中可能含有中英文、符号以及控制符(换行、空格、制表符等)。
Output
按照要求输出美化后的文字段。你不用翻译以上指定的符号之外的所有字符。
Sample Input
Kenny喊道:"我来了!"
Sample Output
Kenny喊道:“我来了!”
Hint
你可以认为所有中文字符由两个字节组成,首字节的ASCII值都大于127(也可以理解为signed char型小于0)#include<stdio.h>
int main()
{
int i,flog;char str[100],str2[3];
while(gets(str)!=NULL)
{
flog=1;
for(i=0;str[i];i++)
{
if(str[i]==',')printf(",");
else if(str[i]=='.')printf("。");
else if(str[i]=='!')printf("!");
else if(str[i]=='?')printf("?");
else if(str[i]=='<'&&str[i+1]=='<'){i++****;printf("《");}
else if(str[i]=='>'&&str[i+1]=='>'){i++****;printf("》");}
else if(str[i]=='"'){if(flog){printf("“");flog=0;}else{printf("”");flog=1;}}
else printf("%c",str[i]);*****
if(str[i]<0)******
{
if(str[i+1]<0){str2[0]=str[i];str2[1]=str[i+1];str2[2]='\0';}
if(!strcmp(str2,"“"))flog=0;
if(!strcmp(str2,"”"))flog=1;
}
}
printf("\n");
}
}
int main()
{
int i,flog;char str[100],str2[3];
while(gets(str)!=NULL)
{
flog=1;
for(i=0;str[i];i++)
{
if(str[i]==',')printf(",");
else if(str[i]=='.')printf("。");
else if(str[i]=='!')printf("!");
else if(str[i]=='?')printf("?");
else if(str[i]=='<'&&str[i+1]=='<'){i++****;printf("《");}
else if(str[i]=='>'&&str[i+1]=='>'){i++****;printf("》");}
else if(str[i]=='"'){if(flog){printf("“");flog=0;}else{printf("”");flog=1;}}
else printf("%c",str[i]);*****
if(str[i]<0)******
{
if(str[i+1]<0){str2[0]=str[i];str2[1]=str[i+1];str2[2]='\0';}
if(!strcmp(str2,"“"))flog=0;
if(!strcmp(str2,"”"))flog=1;
}
}
printf("\n");
}
}