本地通过洛谷0分WA求助
查看原帖
本地通过洛谷0分WA求助
282604
himitsu楼主2020/9/10 19:10
#include <stdio.h>
#include <string.h>
const int maxn = 500010;
char s[maxn] = { '\0' }, ans[maxn] = { '\0' };
int time[26] = { 0 };

int main(void) {
	int t, len, i, max, cnt=0;
	char maxc;
	gets(s);
	while (!strcmp(s, "START")) {
		cnt++;
		gets(s);
		max = 0;
		len = strlen(s);
		for (i = 0; i < len; i++) {
			if (s[i] >= 'a'&&s[i] <= 'z')
				s[i] -= 32;
			if(s[i]>='A'&&s[i]<='Z')
				time[s[i] - 'A']++;
		}
		if (cnt == 1) { // 只需要读入统计第一句中字母的频率来确定密码编制规则,不是每一句一个偏移量
			for (i = 0; i < 26; i++) {
				if (time[i] > max) {
					max = time[i];
					maxc = 'A' + i;
				}
			}
			t = maxc - 'E';
		}
		for (i = 0; i < len; i++) {
			if (s[i] >= 'A'&&s[i] <= 'Z') {
				s[i] -= t;
				if (s[i] < 'A')	s[i] += 26;
				else if (s[i] > 'Z')	s[i] -= 26;
			}
		}
		printf("%s\n", s);
		gets(s);
		gets(s);
	}
	return 0;
}
2020/9/10 19:10
加载中...