题解 | #字符串加解密#
字符串加解密
https://www.nowcoder.com/practice/2aa32b378a024755a3f251e75cbf233a
#include <stdio.h> #include<string.h> int main() { char s1[1000]; char s2[1000]; int len1,len2; int i=0; int j=0; gets(s1); gets(s2); len1=strlen(s1); len2=strlen(s2); while(i<len1) { if(s1[i]>='a'&&s1[i]<'z') { s1[i]=s1[i]-31; } else if(s1[i]=='z') { s1[i]='A'; } else if(s1[i]>='A'&&s1[i]<'Z') { s1[i]=s1[i]+33; } else if(s1[i]=='Z') { s1[i]='a'; } else if(s1[i]>='0'&&s1[i]<'9') { s1[i]=s1[i]+1; } else if(s1[i]=='9'){ s1[i]='0'; } i++; } while(j<len2) { if(s2[j]>'a'&&s2[j]<='z') { s2[j]=s2[j]-33; } else if(s2[j]=='a') { s2[j]='Z'; } else if(s2[j]>'A'&&s2[j]<='Z') { s2[j]=s2[j]+31; } else if(s2[j]=='A') { s2[j]='z'; } else if(s2[j]>'0'&&s2[j]<='9') { s2[j]=s2[j]-1; } else if(s2[j]=='0'){ s2[j]='9'; } j++; } printf("%s",s1); printf("\n"); printf("%s",s2); return 0; }