杭电1736

题意:把一个中英文混合字符串里的英文标点全部改成中文标点。

Analyse:注意到假若是“"(出一个是中文的,后一个是英文的),则应改成“”。

中文字符在C中的储存是一个字占两个char,即在字符串中两个连续的char才表示到一个中文,这两个要连续输出才能正确输出成中文字符。而且要判断字符串中的某个中文字符是不是你想要的字符,要拿出整个连续的两个char(即是一个字符串)来比较。

View Code
 1 #include<stdio.h>
 2 #include<string.h>
 3 int main()
 4 {
 5     char str[30000],temp[3];
 6     int i,open=0;
 7     while(gets(str))
 8     {
 9         for(i=0;str[i]!='\0';i++)
10         {
11             if(str[i]==',')
12                 printf("");
13             else if(str[i]=='.')
14                 printf("");
15             else if(str[i]=='!')
16                 printf("");
17             else if(str[i]=='?')
18                 printf("");
19             else if(str[i]=='<' && str[i+1]=='<')
20             {
21                 printf("");
22                 i++;
23             }
24             else if(str[i]=='>' && str[i+1]=='>')
25             {
26                 printf("");
27                 i++;
28             }
29             else if(str[i]=='"')
30             {
31                 if(open==0)
32                 {
33                     printf("");
34                     open=1;
35                 }
36                 else
37                 {
38                     printf("");
39                     open=0;
40                 }
41             }
42             else
43                 printf("%c",str[i]);
44             if(str[i]<0)
45             {
46                 temp[0]=str[i];
47                 temp[1]=str[i+1];
48                 temp[2]='\0';
49                 if(strcmp(temp,"")==0)
50                     open=1;
51                 else if(strcmp(temp,"")==0)
52                     open=0;
53             }
54         }
55         putchar('\n');
56     }
57     return 0;
58 }
posted @ 2012-07-24 16:28  Hogg  阅读(202)  评论(0)    收藏  举报