您的位置:首页 > 其它

UVa 755 - 487--3279

2010-02-28 19:07 495 查看
/*
coder: ACboy
date: 2010-2-28
result: 1AC
description: UVa 755 - 487--3279
*/

#include <iostream>
#include <string>
#include <algorithm>
using namespace std;

const int MAXN = 100010;
char one[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
char two[] = "2223334445556667N77888999N";

string tel[MAXN];

int cmp(const void * a, const void * b)
{
return strcmp((char *)a, (char *)b) > 0;
}

char binarySearch(char findChar)
{
int begin = 0;
int end = strlen(one);
int mid;
while (begin <= end)
{
mid = (begin + end) / 2;
if (one[mid] == findChar) return two[mid];
else if (one[mid] > findChar) {
end = mid - 1;
}
else {
begin = mid + 1;
}
}
return 'N';
}

void fun(string & to, char from[])
{
int i;
int fromlen = strlen(from);
int c = 0;
for (int i = 0; i < fromlen; i++)
{
if (c == 3) {
to = to + "-";
i--;
c++;
} else {
if (isalpha(from[i]) && from[i] != 'Q' && from[i] != 'Z') {
to.append(1, binarySearch(from[i]));
c++;
} else if (isdigit(from[i])){
to.append(1, from[i]);
c++;
}
}
}
if (c < 3) {
for (i = c; i <= 2; i++)
{
to = to + "0";
}
to += "-";
for (i = 1; i <= 4; i++)
{
to = to + "0";
}
} else if (c == 3){
for (i = 1; i <= 4; i++)
{
to = to + "0";
}
} else if (c > 3 && c < 8) {
for (i = 1; i <= 7 - c; i++)
{
to = to + "0";
}
}
}

int main()
{
int i, j;
int n;
#ifndef ONLINE_JUDGE
freopen("755.txt", "r", stdin);
#endif
scanf("%d", &n);
while (n--)
{
int count;
scanf("%d/n", &count);

for (i = 0; i < count; i++)
{
tel[i].clear();
tel[i].reserve(20);
char temp[20];
gets(temp);
fun(tel[i], temp);
}
sort(tel, tel + count);
int flag = 0;
string current = tel[0];
int num = 1;
for (j = 1; j < count; j++)
{
if (current == tel[j]) num++;
else
{
if (num >= 2) {
cout << tel[j - 1] << " " << num << endl;
num = 1;
current = tel[j];
flag = 1;
} else {
current = tel[j];
num = 1;
}
}
if (j == count - 1 && num >= 2) {
cout << tel[j] << " " << num << endl;
flag = 1;
}
}
if (!flag) {
cout << "No duplicates." << endl;
}
if (n > 0) printf("/n");
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  string fun c 2010