POJ 1002

#include <stdio.h>

#include <stdlib.h>

#include <ctype.h>

#include <string.h>



char index[100002][100];

int  index_i = 0;



int cmp( const void *a, const void *b)

{

	return strcmp( (char*)a, (char*)b );

}



void MapToNum(char des[], char src[])

{

	int j = 0;

	for(int i = 0; src[i] != '\0'; i++)

		if( isdigit(src[i]) )

			des[j++] = src[i];

		else if( isupper(src[i]) )

			if( src[i] <= 'P')

				des[j++] = (src[i] - 'A')/3 + 2 + '0';

			else

			    des[j++] = (src[i] - 'A' - 1)/3 + 2 + '0';

	des[j] = '\0';

}



int main()

{

	freopen("1.txt", "r", stdin);

	int n;

	char str[100], num[100];

	scanf("%d", &n);

	while( n-- )

	{

		scanf("%s", str);

		MapToNum(num, str);

		strcpy(index[index_i++], num);

	}

	qsort(index, index_i, sizeof(index[0]), cmp);

	strcpy(index[index_i], "end");

	

	int count = 1,flag = 0;

	for(int i = 0; i < index_i; i++)

	{

		if( strcmp(index[i],index[i+1]) == 0 )

			count++;

		else if( count > 1)

		{

		    flag = 1;

			for(int j = 0; index[i][j] != '\0'; j++)

				if( j == 3)

					printf("-%c", index[i][j]); 

				else

					printf("%c", index[i][j]);

			printf(" %d\n", count);

			count = 1;

		}

	}

	if(flag == 0)

		printf("No duplicates.\n");

	return 0;

}

蛋疼的一题。输入中竟然可以包含N多个-号。我吐了。。。就数组开小这一问题,我就纠结了一个小时。真浪费时间。。。

你可能感兴趣的:(poj)