| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
为啥总是WA,我机器过了//快排
#include <iostream>
#include <string>
using namespace std;
typedef struct TelInf{
char * TelNum;
int num;
void operator =(const TelInf &);
void operator =(char *);
TelInf(){
TelNum=new char [8];
num=0;
}
TelInf(const TelInf & tel){
TelNum=new char [8];
strcpy(TelNum,tel.TelNum);
num=tel.num;
}
~TelInf(){
delete []TelNum;
}
}TelInf,*TelInfo;
void TelInf::operator =(const TelInf &tel){
TelNum=new char [8];
strcpy(this->TelNum,tel.TelNum);
this->num=tel.num;
}
void TelInf::operator =(char *telnum){
strcpy(this->TelNum,telnum);
this->num++;
}
void ToDigit(char * telnum){
char tel[8];
for(int i=0,j=0;telnum[i];i++){
if (telnum[i]=='-')
continue;
else if(telnum[i]>='0' && telnum[i] <='9')
tel[j++]=telnum[i];
else if(telnum[i]>='A' &&telnum[i]<='R')
tel[j++]=(char)((telnum[i]-'A')/3+'0'+2);
else
tel[j++]=(char)((telnum[i]-'A'-1)/3+'0'+2);
}
tel[j]='\0';
strcpy(telnum,tel);
}
int FindTel(TelInfo tels,char *telnum,int DailNum,int &num){
if(!DailNum)
return 0;
for(int i=0;i<DailNum;i++){
if(strcmp(tels[i].TelNum,telnum)==0){
tels[i].num++;
if (tels[i].num==2)
num++;
return 1;
}
}
return 0;
}
int Partition(TelInfo tels,int low,int high){
TelInf t=tels[low];
char key[8];
strcpy(key,t.TelNum);
while(low<high){
while(low<high && strcmp(key,tels[high].TelNum)<0)
high--;
tels[low]=tels[high];
while(low<high && strcmp(key,tels[low].TelNum)>0)
low++;
tels[high]=tels[low];
}
tels[low]=t;
return low;
}
void QuickSort(TelInfo tels,int low,int high){
if(low>=high)
return;
int pivotloc=Partition(tels,low,high);
QuickSort(tels,low,pivotloc-1);
QuickSort(tels,pivotloc+1,high);
}
int main()
{
int num=0;
int nums;
int DailNum=0;
cin>>nums;
char telnum[16];
TelInfo tels=new TelInf [nums];
int j,i=1;
while (i<=nums){
cin>>telnum;
ToDigit(telnum);
if(!FindTel(tels,telnum,DailNum,num)){
tels[DailNum++]=telnum;
}
i++;
}
if(num==0){
cout<<"No duplicates."<<endl;
return 0;
}
int low=0,high=DailNum-1;
// cout<<DailNum<<endl;
QuickSort(tels,low,high);
int flag;
for(j=0;j<DailNum;j++){
if(tels[j].num>1){
flag=1;
for(i=0;i<8;i++){
if(i==3 && flag){
cout<<"-";
flag=0;
i--;
}
else{
cout<<(tels[j].TelNum)[i];
}
}
cout<<" "<<tels[j].num<<endl;
}
}
return 0;
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator