【HDU】1048 The Hardest Problem Ever

这道题是一道字符串处理的题目,之前接触到的字符串的题目比较少,所以这道题算是耗时比较久的一道题。

*注意*:

1.由于输入中有空格,不宜再使用‘scanf’和‘printf’进行输入输出

2.gets()的使用很重要,需要多加练习

3.解密时需要把所有字母往前移5位,也就是‘-5’,要考虑‘A—E’和‘F—Z’的不同情况

4.一定要用else if,否则会把空格也减5 

#include 
#include 
int main() {
    char a[]="START";
    char b[]="END";
    char c[]="ENDOFINPUT";
    int i,k;
    char s[200];
    while (gets(s)) {    //'gets()'函数
        if (strcmp(s,c)==0)
            break;
        if (strcmp(s,a)==0||strcmp(s, b)==0)    //字符串比较函数'strcmp'
            continue;
        k=strlen(s);    //字符串长度'strlen'
        for(i=0;i='F'&&s[i]<='Z')
                s[i]=s[i]-5;
            else if(s[i]>='A'&&s[i]<='E')  //不要只用else
                s[i]=s[i]+21;
        }
            printf("%s\n",s);
    }
    return 0;
}

你可能感兴趣的:(自学编程)