杭电oj 1328

Tips:本题中没有任何难度,直接按普通逻辑进行计算即可。

 1 #include<stdio.h>
 2 #include<string.h>
 3 char ch[26]={'A','B','C','D','E','F','G',
 4                  'H','I','J','K','L','M','N',
 5                  'O','P','Q','R','S','T',
 6                  'U','V','W','X','Y','Z'};
 7 
 8 int locate(char c)
 9 {   //找出字符在字母表的位置
10     for(int i = 0;i < 26 ;i++)
11     {
12         if(c == ch[i])
13         {
14             return i;
15         }
16     }
17 }
18 
19 int main()
20 {
21     int T;
22     scanf("%d",&T);
23     getchar();//在gets之前先将换行符读取掉
24     for(int i = 1;i <= T;i++)
25     {
26         char a[50];
27         char temp[50];
28         gets(a);
29         for(int j = 0; j < strlen(a);j++)
30         {
31             int l = (locate(a[j])+1)%26;
32             temp[j] = ch[l];
33         }
34         printf("String #%d
",i);
35         for(int j = 0 ;j < strlen(temp);j++)
36             printf("%c",temp[j]);
37         printf("
");
38         printf("
");
39     }
40 
41     return 0;
42 }
原文地址:https://www.cnblogs.com/wujiyang/p/4536861.html