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

能测试的例子全测试过了...为什么还是不对呀...求指导

Posted by Godly at 2012-07-09 13:11:46 on Problem 1002
#include<iostream>
#include<string>
using namespace std;
char* converse(char *a){
	char b[400];
	int len=strlen(a),i,k=0;
	for(i=0;i<len;i++){
		if(a[i]=='A'||a[i]=='B'||a[i]=='C')
			b[k++]='2';
		else if(a[i]=='D'||a[i]=='E'||a[i]=='F')
			b[k++]='3';
		else if(a[i]=='G'||a[i]=='H'||a[i]=='I')
			b[k++]='4';
		else if(a[i]=='J'||a[i]=='K'||a[i]=='L')
			b[k++]='5';
		else if(a[i]=='M'||a[i]=='N'||a[i]=='O')
			b[k++]='6';
		else if(a[i]=='P'||a[i]=='R'||a[i]=='S')
			b[k++]='7';
		else if(a[i]=='T'||a[i]=='U'||a[i]=='V')
			b[k++]='8';
		else if(a[i]=='W'||a[i]=='X'||a[i]=='Y')
			b[k++]='9';
		else if(a[i]=='-')	
			continue;
		else if(a[i]=='Q'||a[i]=='Z')
			b[k++]=a[i];
		else
			b[k++]=a[i];
	}
	b[k]='\0';
	return b;
}
int main(){
	char word[400];
	int i,j,count,int_word[100000],temp,sum,len;
	cin>>count;
	for(i=0;i<count;i++){
		cin>>word;
		int_word[i]=atoi(converse(word));
	}
	for(i=1;i<count;i++){
		for(j=i;j>0;j--){
			if(int_word[j]<int_word[j-1]){
				temp=int_word[j];
				int_word[j]=int_word[j-1];
				int_word[j-1]=temp;
			}
		}
	}
	sum=1;int flag=0;
	for(i=0;i<count;i++){
		if(int_word[i]==int_word[i+1]){
			sum++;
		}
		else if(sum>1){
			flag=1;
			_itoa(int_word[i],word,10);
			len=strlen(word);
			if(len<7){
				if(7-len>=3){
					cout<<"000-";
					for(j=0;j<4-len;j++)
						cout<<'0';
					cout<<word;
				}
				else{
					int m;
					for(j=0;j<7-len;j++)
						cout<<'0';
					for(m=j;m<3;m++)
						cout<<word[m-j];
					cout<<'-';
					for(j=3;j<7;j++)
						cout<<word[j-2];
				}
				cout<<' '<<sum<<endl;
			}
			else{
				for(j=0;j<3;j++)	
					cout<<word[j];
				cout<<'-';
				for(j=3;j<7;j++)
					cout<<word[j];
				cout<<' '<<sum<<endl;
			}
			sum=1;
		}
	}
	if(flag==0)
		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