| ||||||||||
| 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 | |||||||||
Time limited exceed 大家能不能帮忙看一下。#include<iostream.h>
struct mphone
{
int phone;
int num;
};
int mphonenum=0;
void QuickSort(mphone *A,int low,int high)
{ int i,j;
int ok=1;
for(i=low;i<=high-1;i++)
if (A[i].phone>A[i+1].phone)
{
ok=0;
break;
}
if (ok)
return;
mphone temp;
if(low>=high) return;
i=low;j=high;temp=A[i];
while(i<j)
{
while(i<j&&temp.phone<A[j].phone) j--;
if(i<j)
{
A[i++]=A[j];
}
while(i<j&&A[i].phone<=temp.phone) i++;
if(i<j)
{
A[j--]=A[i];
}
}
A[i]=temp;
QuickSort(A,low,--j);
QuickSort(A,++i,high);
}
int main()
{
int num,bit,bitp,phonenum=0,phone;
cin>>num;
cin.get();
char c0;
int *phoneptr=new int[num+1];
mphone *mphoneptr=new mphone[num+2];
mphoneptr[num+1].phone=-1;
for(int i=1;i<=num;i++)
{ phoneptr[i]=0;
mphoneptr[i].phone=-1;
mphoneptr[i].num=0;
bitp=1000000;
c0=cin.get();
while (c0!='\n')
{
if('0'<=c0&&c0<='9')
{
bit=c0-48;
phoneptr[i]+=bit*bitp;
bitp/=10;
}
else if('A'<=c0&&c0<='Z')
{
switch(c0)
{case 'A':case 'B':case 'C':
bit=2;
break;
case 'D':case 'E':case 'F':
bit=3;
break;
case 'G':case 'H':case 'I':
bit=4;
break;
case 'J':case 'K':case 'L':
bit=5;
break;
case 'M':case 'N':case 'O':
bit=6;
break;
case 'P':case 'R':case 'S':
bit=7;
break;
case 'T':case 'U':case 'V':
bit=8;
break;
case 'W':case 'X':case 'Y':
bit=9;
break;
default:
bit=0;
break;
}
phoneptr[i]+=bit*bitp;
bitp/=10;
}
c0=cin.get();
}
}
for(i=1;i<=num;i++)
{
phone=phoneptr[i];
if (phone!=-1)
{
phonenum=0;
for(int j=1;j<=num;j++)
if (phone==phoneptr[j])
{
phoneptr[j]=-1;
phonenum++;
}
if (phonenum>=2)
{
mphonenum++;
mphoneptr[mphonenum].phone=phone;
mphoneptr[mphonenum].num=phonenum;
}
}
}
QuickSort(mphoneptr,1,mphonenum);
for(i=1;i<=mphonenum;i++)
cout<<mphoneptr[i].phone/10000<<"-"<<mphoneptr[i].phone%10000<<' '<<mphoneptr[i].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