Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

C code

Posted by ayxg at 2011-12-07 14:19:50 on Problem 1002
#include <stdio.h>
#include <stdlib.h>
const char map[26] = { '2', '2', '2', '3', '3', '3', '4', '4', '4', '5', '5', '5', 
						'6', '6', '6', '7', '\0', '7', '7', '8', '8', '8', '9', '9', '9' };
int set[100000]; int setLen = 0;
int _cmp(const void* e1, const void* e2) { return ( *((int*)e1) - *((int*)e2) ); }
int main()
{
	int i, n, t, pos, flag;
	char tstr[64]; scanf("%d", &n);
	while (n > 0) {
		scanf("%s", tstr); pos = 0;
		for (i = 0; pos < 7; ++i)
			if ( tstr[i] >= 'A' && tstr[i] <= 'Y' && tstr[i] != 'Q' ) tstr[pos++] = map[tstr[i]-'A'];
			else if ( tstr[i] >= '0' && tstr[i] <= '9' ) tstr[pos++] = tstr[i];
		tstr[pos] = '\0'; sscanf(tstr, "%d", &t); set[setLen++] = t; --n;
	}
	qsort(set, setLen, sizeof(int), _cmp); flag = 1;
	for (i = 0; i < setLen - 1; ++i) { 
		t = 1; while (set[i] == set[i+1]) { ++i; ++t; }
		if (t > 1) { printf("%03d-%04d %d\n", set[i]/10000, set[i]%10000, t); flag = 0; }
	}
	if (flag) printf("No duplicates. \n");
	return 0;
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator