Photolog

Through the Looking-Glass
2010-10-12: Through the Looking-Glass
My radio speaks is binary!
2010-10-10: My radio speaks is binary!
Gigaminx: (present for my birthday)
2010-09-16: Gigaminx: (present for my birthday)
Trini on bike
2010-09-05: Trini on bike
Valporquero
2010-08-28: Valporquero
My new bike!
2010-08-22: My new bike!
Mario and Ana's wedding
2010-08-13: Mario and Ana's wedding
Canyoning in Guara
2010-08-07: Canyoning in Guara
Trini and Mari in Marbella
2010-08-05: Trini and Mari in Marbella
Trini and Chelo in Tabarca
2010-08-03: Trini and Chelo in Tabarca
Valid XHTML 1.1
Log in
Back to list of problems

What's Cryptanalysis?

10008.c

/* 10008 - What's Cryptanalysis? */

#include <stdio.h>
#include <string.h>
#include <ctype.h>

int let[255];

void
process(char * str) {
	while (*str) {
		if (isalpha(*str)) {
			*str = toupper(*str);
			let[(int)*str]++;
		}
		str++;
	}
}

void
calc(void) {
	while (1) {
		int i;
		int l,nl=0;

		for (i='A'; i<='Z'; i++) {
			if (let[i] > nl) {
				l = i;
				nl = let[i];
			}
		}
		if (!nl) {
			break;
		}
		let[l] = 0;
		printf("%c %d\n", l, nl);
	}
}

int
main(void) {
	int n;
	int i;
	char buf[10240];
	memset(let, 0, sizeof(let));

	fgets(buf, 1024, stdin);
	sscanf(buf, "%d", &n);
	for (i=0; i<n; i++) {
		fgets(buf, 10240, stdin);
		process(buf);
	}
	calc();
	return 0;
}