2021CSPJ1 17题阅读程序
  • 板块灌水区
  • 楼主zxm_
  • 当前回复8
  • 已保存回复8
  • 发布时间2022/9/12 14:16
  • 上次更新2023/10/27 11:52:20
查看原帖
2021CSPJ1 17题阅读程序
731974
zxm_楼主2022/9/12 14:16
#include <stdio.h>
#include <string.h>
char base[64];
char table[256];
char str[256];
char ans[256];
void init(){
	for (int i = 0; i < 26; i++) base[i] = 'A' + i;
	for (int i = 0; i < 26; i++) base[26 + i] = 'a' + i;
	for (int i = 0; i < 10; i++) base[52 + i] = '0' + i;
	base[62] = '+', base[63] = '/';
	for (int i = 0; i < 256; i++) table[i] = 0xff;
	for (int i = 0; i < 64; i++) table[base[i]] = i;
	table['='] = 0;
}
void decode(char *str){
	char *ret = ans;
	int i, len = strlen(str);
	for (i = 0; i < len; i += 4) {
			(*ret++) = table[str[i]] << 2 | table[str[i + 1]] >> 4;
		if (str[i + 2] != '=')
			(*ret++) = (table[str[i + 1]] & 0x0f) << 4 | table[str[i + 2]] >> 2;
		if(str[i + 3] != '=')
			(*ret++) = table[str[i + 2]] << 6 | table[str[i + 3]];
	}
}
int main(){
	init();
	printf("%d\n", (int)table[0]);
	scanf("%s", str);
	decode(str);
	printf("%s\n", ans);
	return 0;
}

跪求

(*ret++) = (table[str[i + 1]] & 0x0f) << 4 | table[str[i + 2]] >>

是什么意思

2022/9/12 14:16
加载中...