题解 | #简单密码#
简单密码
http://www.nowcoder.com/practice/7960b5038a2142a18e27e4c733855dac
#include<ctype.h>
void dealUpper(char *ch);
void dealUpper(char *ch) {
if(*ch == 'Z') {
*ch = 'a';
}
else {
*ch = *ch + 'a'-'A' + 1;
}
}
int main(void) {
char s[100] = "";
int i = 0;
int count = 2;
int k = 0;
char ar[128] = {0};
for(i = 'a'; i <= 'z'; i++) {
ar[i] = count + '0';
k++;
if(i == 'r' || i == 'y') {
k--;
}
else if(k == 3) {
count++;
k = 0;
}
}
gets(s);
for(i = 0; i < strlen(s); i++) {
if(isupper(s[i])) {
dealUpper(s+i);
}
else if(islower(s[i])) {
s[i] = ar[s[i]];
}
}
puts(s);
return 0;
}