| ||||||||||
| 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 <stdlib.h>
#include <math.h>
using namespace std;
const int MAX = 200000;
void TransToNum(const char* str, int *a)
{
for (int i = 0 ; i < strlen(str); i++)
{
if ('-' == str[i])
{
continue;
}
else if (('0' <= str[i]) && ('9' >= str[i]))
{
*a = (*a)*10 + static_cast<int>(str[i] - '0');
}
else
{
switch(str[i])
{
case 'A':
case 'B':
case 'C':
*a = (*a)*10 + 2;
break;
case 'D':
case 'E':
case 'F':
*a = (*a)*10 + 3;
break;
case 'G':
case 'H':
case 'I':
*a = (*a)*10 + 4;
break;
case 'J':
case 'K':
case 'L':
*a = (*a)*10 + 5;
break;
case 'M':
case 'N':
case 'O':
*a = (*a)*10 + 6;
break;
case 'P':
case 'R':
case 'S':
*a = (*a)*10 + 7;
break;
case 'T':
case 'U':
case 'V':
*a = (*a)*10 + 8;
break;
case 'W':
case 'X':
case 'Y':
*a = (*a)*10 + 9;
break;
default:
return;
}
}
}
}
int cmp(const void*a,const void*b)//快排自定义cmp
{
return *(int*)a-*(int*)b;
}
int main()
{
int n;
int m;
int j;
char strInput[256];
int result[MAX];
bool hasNum;
m = 0;
hasNum = false;
memset(result, 0, sizeof(int)*MAX);
cin>>n;
for (int i=0; i<n; i++)
{
cin>>strInput;
TransToNum(strInput, &result[m++]);
}
qsort(result,n,sizeof(int),cmp);
for(size_t i=0; i<n-1; i++)
{
j = i;
while(result[i] == result[i+1])
{
i++;
}
if (i != j)
{
cout<<result[i]/10000<<"-";
cout<<result[i]%10000;
cout<<" "<<i-j+1<<endl;
hasNum = true;
}
}
if (!hasNum)
{
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