解题思路:寻找规律
注意事项:
参考代码:
void test(char *s1,char *s2,int m,int n){ static char s[1001]; int i; for(i=0;i<n;i++){ if(s2[i]>=65 && s2[i]<=90){ if(s1[i%m]>=97 && s1[i%m]<=122){ if(s2[i]-(s1[i%m]-32)>=0){ s[i] = s2[i]-(s1[i%m]-32)+'A'; } else{ s[i] = s2[i]-(s1[i%m]-32) + 26+'A'; } } else{ if(s2[i]-s1[i%m]>=0){ s[i] = s2[i] - s1[i%m] +'A'; } else{ s[i] = s2[i] - s1[i%m] +26+'A'; } } } else{ if(s1[i%m]>=65 && s1[i%m]<=90){ if(s2[i]-(s1[i%m]+32)>=0){ s[i] = s2[i]-(s1[i%m]+32)+'a'; } else{ s[i] = s2[i]-(s1[i%m]+32) + 26+'a'; } } else{ if(s2[i]-s1[i%m]>=0){ s[i] = s2[i] - s1[i%m] +'a'; } else{ s[i] = s2[i] - s1[i%m] +26+'a'; } } } } s[n]=0; printf("%s\n",s); } int main(){ char s1[101]; //密钥字符串 char s2[1001]; //密文字符串 int m,n; scanf("%s",s1); scanf("%s",s2); m = strlen(s1); n = strlen(s2); test(s1,s2,m,n); system("pause"); return 0; }
0.0分
0 人评分