1002

#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
int comp(const void *a,const void *b)
{
return *(int *)a-*(int *)b;
}
char charDigram(char c)
{
char temp=c;
char result;
switch(temp)
{
case '0': result= '0';break;
case '1': result= '1';break;
case '2': result= '2';break;
case '3': result= '3';break;
case '4': result= '4';break;
case '5': result= '5';break;
case '6': result= '6';break;
case '7': result= '7';break;
case '8': result= '8';break;
case '9': result= '9';break;
case 'A': result= '2';break;
case 'B': result= '2';break;
case 'C': result= '2';break;
case 'D': result= '3';break;
case 'E': result= '3';break;
case 'F': result= '3';break;
case 'G': result= '4';break;
case 'H': result= '4';break;
case 'I': result= '4';break;
case 'J': result= '5';break;
case 'K': result= '5';break;
case 'L': result= '5';break;
case 'M': result= '6';break;
case 'N': result= '6';break;
case 'O': result= '6';break;
case 'P': result= '7';break;
case 'R': result= '7';break;
case 'S': result= '7';break;
case 'T': result= '8';break;
case 'U': result= '8';break;
case 'V': result= '8';break;
case 'W': result= '9';break;
case 'X': result= '9';break;
case 'Y': result= '9';break;
default: break;
}
return result;
}
void swap(int & i,int & j)
{
int temp=i;
i=j;
j=temp;
}
int getPivot(int array[],int left,int right)
{
int middle=(left+right)/2;
if(array[left]>array[middle])
swap(array[left],array[middle]);
if(array[left]>array[right])
swap(array[left],array[right]);
if(array[middle]>array[right])
swap(array[middle],array[right]);
swap(array[middle],array[right]);
int result=array[right];
return result;
}
int doPartition(int array[],int left,int right, int pivot)
{
int i=left;
int j=right-1;
while(true)
{
while(array[i]<pivot)
++i;
while(array[j]>=pivot)
--j;
if(i>=j)
break;
else
{
swap(array[i],array[j]);
}
}
swap(array[i],array[right]);
return i;
}
void insertSort(int array[],int left,int right)
{
for(int i=left+1;i<=right;++i)
{
int temp=array[i];
int j=i;
while(j>left&&array[j-1]>=temp)
{
array[j]=array[j-1];
--j;
}
if(j!=i)
{
array[j]=temp;
}
}
}
void quickSort(int array[],int left,int right)
{
int size=right-left+1;
/*if(size<9)
{
insertSort(array,left,right);
return;
}
else*/
if(left<=right)
{
int pivot= getPivot(array,left,right);
int position=doPartition(array,left,right,pivot);
//cout<<pivot<<position<<endl;
quickSort(array,left,position-1);
//cout<<"asdfgh"<<endl;
quickSort(array,position+1,right);
}
}
int transform(string str,int * array,int i)
{
string s=str;
string temp;
char c;
for(int j=0;j<str.size();++j)
{
char tempc=str.at(j);
if(tempc!='-')
{
c=charDigram(tempc);
temp+=c;
}
}
const char *result=temp.c_str();
array[i]=atoi(result);
return 1;
}
int count(int array[],int n)
{
int temp=1;
int *count;
count=new int[n];
for(int i=0;i<n;++i)
{
count[i]=0;
}
for(int i=1;i<n;++i)
{
if(array[i]==array[i-1])
{
temp++;
}
else
{
count[i-1]=temp;
temp=1;
}
}
count[n-1]=temp;
int countForDup=0;
for(int j=0;j<n;++j)
{
if(count[j]!=0&&count[j]!=1)
{
countForDup++;
int tempx=0;
int tempy=0;
tempx=array[j]/10000;
tempy=array[j]%10000;
if(tempx<100)
cout<<'0';
if(tempx<10)
cout<<'0';
cout<<tempx<<'-';
if(tempy<1000)
cout<<'0';
if(tempy<100)
cout<<'0';
if(tempy<10)
cout<<'0';
cout<<tempy<<' '<<count[j]<<endl;
/*if(array[j]/10000<100)cout<<'0';
if(array[j]/10000<10)cout<<'0';
cout<<array[j]/10000<<'-';
if(array[j]%10000<1000)cout<<'0';
if(array[j]%10000<100)cout<<'0';
if(array[j]%10000<10)cout<<'0';
cout<<array[j]%10000<<' '<<count[j]<<endl;*/
}
}
if(countForDup==0)
{
cout<<"No duplicates."<<endl;
}
return 0;
}
int main()
{
int NUM=0;
string str;
//while(cin>>NUM)
cin>>NUM;
//{
int n=NUM;
int *array;
array=new int[n];
for (int i=0;i<n;++i)
{
cin>>str;
transform(str,array,i);
}
quickSort(array,0,n-1);
//qsort(array,n,sizeof(int),comp);
count(array,n);
//}
return 1;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值