简单字符串处理~

1.定义字符数组 char a[N]; 注意:N必须要是常量!!

2字符数组与字符串本质相同,char a[20],b[20];则gets(a);与scanf("%s%s",a,b)作为字符串的输入;

3经常利用strcmp(str1,str2)作为判断、循环条件。str1>str2,返回正数;st1=str2,返回0;str1<str2,返回负数。

4字母A~Z:65~91;a~z:97~123;

5题目链接:http://acm.split.hdu.edu.cn/showproblem.php?pid=1048

 1 #include <stdio.h>
 2 #include <string.h>
 3 int main()
 4 {
 5     char a[10],b[100],c[10];
 6     int j;
 7     for(;;)
 8     {
 9         gets(a);
10         if(!strcmp(a,"START"))
11         {
12             gets(b);
13             gets(c);
14             if(!(strcmp(c,"END")))
15             {
16                 for(j=0;b[j]!='\0';j++)
17                 {
18                     if(b[j]>='F' && b[j]<='Z')
19                         b[j]=b[j]-5;
20                     else if(b[j]>='A' && b[j]<='E')
21                         b[j]=b[j]+21;
22                 }
23             }
24             printf("%s\n",b);
25         }
26         else if(!strcmp(a,"ENDOFINPUT"))
27         break;
28     }
29     return 0;
30 }
View Code

 

posted @ 2017-01-19 18:17  bigdapi  阅读(106)  评论(0)    收藏  举报