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

总是wrong answer!为什么?(附代码)高手帮帮忙!

Posted by cfox at 2006-03-18 12:36:51 on Problem 1002
#include <iostream>
#include <cstdlib>
#include <string>
#include <memory>
#include <iomanip>
using namespace std;

int compare(const void * a,const void * b)
{
	return *((int*)a)-*((int*)b);
}

int main(){
	int n,m=1;
	int a[100000];
	memset(a,-1,100000*sizeof(int));
	cin >>n;
	for(int k=0;k<n;k++){
		char str[16],num[8];
		memset(num,'\0',sizeof(num));
		cin >>str;
		int len=strlen(str),j=0;
		for(int i=0;i<len;i++){
			switch(str[i]){
			case 'A':num[j]='2';j++;break;
			case 'B':num[j]='2';j++;break;
			case 'C':num[j]='2';j++;break;
			case 'D':num[j]='3';j++;break;
			case 'E':num[j]='3';j++;break;
			case 'F':num[j]='3';j++;break;
			case 'G':num[j]='4';j++;break;
			case 'H':num[j]='4';j++;break;
			case 'I':num[j]='4';j++;break;
			case 'J':num[j]='5';j++;break;
			case 'K':num[j]='5';j++;break;
			case 'L':num[j]='5';j++;break;
			case 'M':num[j]='6';j++;break;
			case 'N':num[j]='6';j++;break;
			case 'O':num[j]='6';j++;break;
			case 'P':num[j]='7';j++;break;
			case 'R':num[j]='7';j++;break;
			case 'S':num[j]='7';j++;break;
			case 'T':num[j]='8';j++;break;
			case 'U':num[j]='8';j++;break;
			case 'V':num[j]='8';j++;break;			
			case 'W':num[j]='9';j++;break;
			case 'X':num[j]='9';j++;break;
			case 'Y':num[j]='9';j++;break;
			}
			if(str[i]>='0'&&str[i]<='9'){
				num[j]=str[i];
			j++;
			}
		}
		a[k]=atoi(num);
	}
	qsort(a,n,sizeof(int),compare);
	for(int i=0;i<n;){
		int l=1;
		for(int j=i+1;a[i]==a[j];j++)l++;
		if(l>1){
			cout<<setfill('0')<<setw(3)<<a[i]/10000<<"-"<<setfill('0')<<setw(4)<<a[i]%10000<<" "<<l<<endl;
			m=0;
		}
		i=j;
	}
	if(m)cout<<"No duplicates."<<endl;
	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