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

不知为何一直是WA? 求指点

Posted by TomMengdel at 2013-01-21 22:23:21 on Problem 1002
#include<iostream>
#include<algorithm>
#include<cstdlib>
#include<cstdio>
#include<cctype>
#include<cstring>
using namespace std;
const int N = 110000;
inline char translate(char c) { //这个转换函数应该用数组实现。
	char ret = c;
	switch(c) {
		case 'A': case 'B' : case 'c':
			ret = '2';
			break;
		case 'D':case 'E':case 'F':
			ret = '3'; break;
		case 'G':case 'H':case 'I':
			ret = '4'; break;
		case 'J':case 'K': case 'L':
			ret = '5'; break;
		case 'M':case 'N': case 'O':
			ret = '6'; break;
		case 'P':case 'R': case 'S':
			ret = '7'; break;
		case 'T':case 'U': case 'V':
			ret = '8'; break;
		case 'W':case 'X': case 'Y':
			ret = '9'; break;
	}
	return ret;
}
//CMP的功能: 前者大于后者

int cmp(const void *a, const void *b) {
	return strcmp(*(char **)a, *(char **)b);
}


int main() {
	int n;
	cin>>n;
	char nums[N][8];
	int count;
	for(int i = 0; i < n; i++) {
		int k = 0; char c;
		while(k != 7) {
			scanf("%c", &c);
			if(isalnum(c)) nums[i][k++] = translate(c);			
		}
		nums[i][k] = '\0';
	}
	//Start to sort; use quicksort
	char *numsptr[N];
	for(int i = 0; i < n; i++) numsptr[i] = nums[i];
	
	qsort(numsptr, n, sizeof(char *),cmp);
//	for(int i = 0; i < n; i++) printf("%s\n", numsptr[i]);
	int i = 0, dup = 1;
	bool existdup = false;

	for(int i = 1; i < n; i++) {

		if(strcmp(numsptr[i],numsptr[i - 1]) == 0) dup++;
		else if((strcmp(numsptr[i],numsptr[i - 1]) != 0) && dup > 1) {
			existdup = true;
			printf("%c%c%c-%c%c%c%c %d\n", numsptr[i - 1][0],numsptr[i - 1][1],numsptr[i - 1][2],numsptr[i - 1][3],numsptr[i - 1][4],numsptr[i - 1][5],numsptr[i - 1][6], dup);
		dup = 1;
		}
	}
	
	if(!existdup)cout<<"No duplicates."<<endl;
	
}
//实在是不明白自己到底错在哪里?

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