题目意思:
加密方法:
每个字母在字母表中都对应着一个整数(在字母表中的位置),而每一个整数又对应着一个二进制数字,我们的加密算法会在这个二进制数字前面加上0前缀,使得前缀0的个数和原本二进制数的位数之和为5,然后0被替换为一个随机大写字母 1被替换为一个随机数字,这样我们的加密就完成了
解码就是反过来做而已,看到大写字母就当做0来处理,看到数字就当做1来处理,对于这个我们只需要使用isdigit和isalpha函数即可
不行,我好想爆粗口,这题真TM坑,既然要多组数据,为什么不在题目描述中写出来,这不是坑人吗????
#include<stdio.h>
#include<math.h>
#include<string.h>
#include<ctype.h>
int main() {
int t;
char str[10010];
while(~scanf("%d", &t)) {
memset(str, '\0', sizeof(str));
scanf("%s", str);
int tmp[10];
memset(tmp, 0, sizeof(tmp));
int result[10000];
memset(result, 0, sizeof(result));
int coount = 0;
int cpunt = 0;
for(int i = 0 ; i< t; i++) {
if (isdigit(str[i])) {
tmp[cpunt++] = 1;
} else if(isalpha(str[i])) {
tmp[cpunt++] = 0;
}
if(cpunt == 5) {
cpunt = 0;
int summ = 0;
for(int jj = 0 ; jj <5 ; jj++) {
tmp[jj]*=pow(2,(4-jj));
summ+=tmp[jj];
}
result[coount++]=summ;
}
}
for(int i= 0 ; i<coount; i++)
printf("%c", 65+result[i]);
printf("\n");
}
return 0;
}