Start: Dec, 04, 2016 12:00:00
杭州师范大学第十届程序设计竞赛—正式
End: Dec, 04, 2016 17:00:00
Time elapsed:
Time remaining:

Problem_ID: D
Result: Accepted
Time: 0ms
Memory: 1096kB
In contest: 1075

#include <stdlib.h>
#include <stdio.h>
typedef struct node* nodePointer;
typedef struct node {
	char name[22];
	int key;
	int coffee;
	int game;
	int queue;
};

int compgame(const void *p, const void *q) {
	if (((node *)q)->game > ((node *)p)->game)
			return 1;
	if (((node *)q)->game == ((node *)p)->game)
		if (((node *)q)->queue < ((node *)p)->queue)
			return 1;
	return 0;
}

int compcoffee(const void *p, const void *q) {
	if (((node *)q)->coffee > ((node *)p)->coffee)
			return 1;
	if (((node *)q)->coffee == ((node *)p)->coffee)
		if (((node *)q)->queue < ((node *)p)->queue)
			return 1;
	return 0;
}

int compkey(const void *p, const void *q) {
	if (((node *)q)->key > ((node *)p)->key)
			return 1;
	if (((node *)q)->key == ((node *)p)->key)
		if (((node *)q)->queue < ((node *)p)->queue)
			return 1;
	return 0;
}

int type(char num[]) {
	int i, sum = 0;
	for(i = 0; i < 6; i++)
		sum += num[i];
	if(sum == num[0] * 6)
		return 1;
	char temp = num[0];
	bool flag = true;
	for(i = 1; i < 6; i++) {
		if (temp - num[i] <= 0) {
			flag = false;
			break;
		}
		temp = num[i];
	}
	if(flag)
		return 2;
	return 3;
}

int main() {
	int n, i;
	scanf("%d", &n);
	nodePointer f = (nodePointer)malloc(sizeof(node) * n);
	for (i = 0; i < n; i++) {
		int ownnumber;
		scanf("%d%s", &ownnumber, &f[i].name);
		f[i].coffee = f[i].game = f[i].key = 0;
		f[i].queue = i;
		while(ownnumber--) {
			char number[7], temp[9];
			scanf("%s", temp);
			int k = 0;
			for (int j = 0; j < 8; j++) {
				if (j != 2 && j != 5)
					number[k++] = temp[j];
			}
			number[6] = '\0';
			if (type(number) == 1)
				(f[i].key)++;
			else if (type(number) == 2)
				(f[i].game)++;
			else if (type(number) == 3)
				(f[i].coffee)++;
		}
	}
	
	qsort(f, n, sizeof(node), compkey);
	printf("If you want to have a keyboard, you should call:");
	printf(" %s", f[0].name);
	for (int k = 1; k < n; k++) {
		if (f[k].key == f[0].key)
			printf(", %s", f[k].name);
	}
	printf(".\n");

	qsort(f, n, sizeof(node), compgame);
	printf("If you want to order a Watchdog2, you should call:");
	printf(" %s", f[0].name);
	for (int k = 1; k < n; k++) {
		if (f[k].game == f[0].game)
			printf(", %s", f[k].name);
	}
	printf(".\n");

	qsort(f, n, sizeof(node), compcoffee);
	printf("If you want to have a cup of coffee with a girl, you should call:");
	printf(" %s", f[0].name);
	for (int k = 1; k < n; k++) {
		if (f[k].coffee == f[0].coffee)
			printf(", %s", f[k].name);
	}
	printf(".\n");
	return 0;
}