martes, 25 de octubre de 2011

10226 - Hardwood Species, uva

#include<iostream>
#include<cstring>
#include<cstdio>
#include<map>
#include<cstdlib>
#define foreach(it, l) for (typeof(l.begin()) it = l.begin(); it != l.end(); it++)
#define db(a) cout << #a << " = " << a << endl
using namespace std;
int main() {
	char linea[30];
	void *p;
	gets(linea);
	int test = atoi(linea), total;
	gets(linea);
	for (int i = 0; i < test; i++) {
		if (i != 0) printf("\n");
		map mapa;
		while (1) {
			p = gets(linea);
			if(p == NULL || linea[0] == '\0') break;
			if (strcmp(linea, "") == 0) break;
			mapa[linea]++;
		}
		total = 0;
		foreach(it, mapa) {
			total += it->second;
		}
		foreach(it, mapa) {
			printf("%s %.4f\n", it->first.c_str(), ( (double)it->second * 100 )/ total);
		}
	}
	return 0;
}

No hay comentarios:

Publicar un comentario