PTA 乙级 1095 解码PAT准考证

完结撒花!!
下学期学过数据结构后会把甲级题目写掉。

#include
#include
#include

typedef struct
{
	int classroom, date, idnum, score, cnt;
	char rank, allnum[14];
}information;

int str_to_int(char *str, int N)
{
	int result = 0;

	for (int i = 0; i < N; i++)
		result += (str[i] - '0')*pow(10, N - i - 1);

	return result;
}

int cmp_1(const void *a, const void *b)
{
	information *aa = (information*)a, *bb = (information*)b;
	if (aa->score != bb->score)
		return aa->score > bb->score ? -1 : 1;
	else return strcmp(aa->allnum, bb->allnum);
}

int cmp_3(const void *a, const void *b)
{
	information *aa = (information*)a, *bb = (information*)b;
	if (aa->cnt != bb->cnt)
		return aa->cnt > bb->cnt ? -1 : 1;
	else return aa->classroom > bb->classroom ? 1 : -1;
}

int main()
{
	int N, M;

	scanf("%d %d", &N, &M);
	information *array = (information*)malloc(sizeof(information)*N);
	for (int i = 0; i < N; i++)
	{
		char num[14]; int score;
		scanf("%s %d", num, &score);
		array[i].rank = num[0], array[i].classroom = str_to_int(num + 1, 3);
		array[i].date = str_to_int(num + 4, 6), array[i].idnum = str_to_int(num + 10, 3);
		array[i].score = score, strcpy(array[i].allnum, num);
	}
	qsort(array, N, sizeof(information), cmp_1);
	for (int i = 0; i < M; i++)
	{
		int c;
		scanf("%d", &c); 
		if (c == 1)
		{
			char rank[2]; int flag = 0;
			scanf("%s", rank);
			printf("Case %d: 1 %s\n", i + 1, rank);
			for(int j=0;j

你可能感兴趣的:(PTA,Basic,Level,Practice)