| ||||||||||
| 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>
using namespace std;
char changeCharToInt(char &c)
{
switch(c)
{
case 'A':case 'B':case 'C':return '2';
case 'D':case 'E':case 'F':return '3';
case 'G':case 'H':case 'I':return '4';
case 'J':case 'K':case 'L':return '5';
case 'M':case 'N':case 'O':return '6';
case 'P':case 'R':case 'S':return '7';
case 'T':case 'U':case 'V':return '8';
case 'W':case 'X':case 'Y':return '9';
}
}
int cmp(const void *a,const void *b)
{
return (*(int *)a-*(int *)b);
}
int main()
{
int nums;
cin>>nums;
char (*phone)[20]=new char[nums][20];
char (*tel)[8] = new char[nums][8];
int *num = new int[nums];
int i =0;
while(i<nums)
cin>>phone[i++];
int length,j = 0,k=0;
i = 0;
while(i<nums)
{
length = strlen(phone[i]);
while(j<length)
{
if(phone[i][j]=='-')
{
j++;
}else {
if(phone[i][j]>='0'&&phone [i][j]<='9')
tel[i][k++]=phone[i][j++];
else
tel[i][k++] = changeCharToInt(phone[i][j++]);
}
}
tel[i][k]= '\0';
i++;
k=0;
j=0;
}
i = 0;
while(i<nums)
num[i++] = atoi(tel[i]);
qsort(num,nums,sizeof(num[0]),cmp);
i = 1;
int t = 1;
int flag = 0;
while(i<nums)
{
if(num[i]!=num[i-1])
{
if(t>1)
{
printf("%03d-%04d %d\n",num[i-1]/10000,num[i-1]%10000,t);
flag = 1;
}
t = 1;
}else
t++;
i++;
}
if(!flag)
cout<<"No duplicates. "<<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