#include <iostream>
#include <string>
#include <map>
#include <algorithm>
#include <cstdio>
#include <cctype>
using namespace std; const char kTable[] = "2223334445556667Q77888999Z";
int main()
{
int T;
cin >> T;
bool first_output(true);
while(T--)
{
int n; cin >> n;
map<string, int> r;
for(int i = ; i <= n; i++)
{
string t; cin >> t;
t.erase(remove(t.begin(), t.end(), '-'), t.end());
for(int j = ; j < t.size(); j++)
if(!isdigit(t[j]))
t[j] = kTable[t[j]- 'A'];
t.insert(, "-");
r[t]++;
}
if(first_output)
first_output = false;
else cout << endl;
bool found(false);
for(map<string, int>::iterator it = r.begin(); it != r.end(); it++)
if( it->second > )
{
cout << it->first << " " << it->second << endl;
found = true;
}
if(!found) cout << "No duplicates." << endl;
}
return ;
}

另一种解法:

先將每一種不同格式的電話號碼全部換成7位數整數,
利用一個hash紀錄每一種電話號碼的出現的次數,
將出現兩次以上的電話號碼紀錄到一個陣列裡面,
再利用quicksort將這個陣列以電話號碼來排序,
最後從頭將電話號碼及其出現的次數輸出來即可。

 #include<stdio.h>
#include<string.h>
#include<ctype.h> void quicksort( int start, int end, int array[] )
{
if( start < end )
{
int change = start;
int i;
int temp;
for( i = start+ ; i < end ; i++ )
if( array[i] < array[start] )
{
change++; temp = array[i];
array[i] = array[change];
array[change] = temp;
} temp = array[start];
array[start] = array[change];
array[change] = temp; quicksort( start, change, array );
quicksort( change+, end, array );
}
} int hash_numbers[] = {}; int main()
{
int datasets;
int blank;
while( scanf( "%d", &datasets ) != EOF )
{
blank = ;
int numbers; while( datasets-- )
{
scanf( "%d", &numbers );
getchar(); int i;
memset( hash_numbers, , sizeof(hash_numbers) );
int output[] = {};
int output_saved = ;
for( i = ; i < numbers ; i++ )
{
char tempnum[];
gets( tempnum ); int templen = strlen( tempnum );
int tempnumint = ;
int j;
for( j = ; j < templen ; j++ )
{
if( isalnum( tempnum[j] ) )
{
tempnumint *= ;
if( isdigit( tempnum[j] ) )
tempnumint += (int)(tempnum[j] - '');
else
{
switch( tempnum[j] )
{
case 'A': case 'B': case 'C':
tempnumint += ;
break;
case 'D': case 'E': case 'F':
tempnumint += ;
break;
case 'G': case 'H': case 'I':
tempnumint += ;
break;
case 'J': case 'K': case 'L':
tempnumint += ;
break;
case 'M': case 'N': case 'O':
tempnumint += ;
break;
case 'P': case 'R': case 'S':
tempnumint += ;
break;
case 'T': case 'U': case 'V':
tempnumint += ;
break;
case 'W': case 'X': case 'Y':
tempnumint += ;
break;
}
}
}
}
hash_numbers[tempnumint]++;
if( hash_numbers[tempnumint] == )
output[output_saved++] = tempnumint;
}
quicksort( , output_saved, output ); if( blank )
printf( "\n" );
blank = ; for( i = ; i < output_saved ; i++ )
printf( "%03d-%04d %d\n", output[i]/, output[i]%, hash_numbers[output[i]] );
if( output_saved == )
printf( "No duplicates.\n" );
}
}
return ;
}

uva 755 - 487--3279的更多相关文章

  1. 开篇,UVA 755 && POJ 1002 487--3279 (Trie + DFS / sort)

    博客第一篇写在11月1号,果然die die die die die alone~ 一道不太难的题,白书里被放到排序这一节,半年前用快排A过一次,但是现在做的时候发现可以用字典树加深搜,于是乐呵呵的开 ...

  2. POJ 1002 UVA 755 487--3279 电话排序 简单但不容易的水题

    题意:给你许多串字符串,从中提取电话号码,输出出现复数次的电话号码及次数. 以下是我艰难的AC历程:(这题估计是我刷的题目题解次数排前的了...) 题目不是很难理解,刚开始想到用map,但stl的ma ...

  3. UVA - 10375 Choose and divide[唯一分解定理]

    UVA - 10375 Choose and divide Choose and divide Time Limit: 1000MS   Memory Limit: 65536K Total Subm ...

  4. UVA 11997 STL 优先队列

    题目链接: http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem ...

  5. 【暑假】[深入动态规划]UVa 1412 Fund Management

    UVa 1412 Fund Management 题目: UVA - 1412 Fund Management Time Limit: 3000MS   Memory Limit: Unknown   ...

  6. POJ.3279 Fliptile (搜索+二进制枚举+开关问题)

    POJ.3279 Fliptile (搜索+二进制枚举+开关问题) 题意分析 题意大概就是给出一个map,由01组成,每次可以选取按其中某一个位置,按此位置之后,此位置及其直接相连(上下左右)的位置( ...

  7. 【枚举】POJ 3279

    直达–>POJ 3279 Fliptile 题意:poj的奶牛又开始作孽了,这回他一跺脚就会让上下左右的砖块翻转(1->0 || 0->1),问你最少踩哪些砖块才能让初始的砖块全部变 ...

  8. uva 1354 Mobile Computing ——yhx

    aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAABGcAAANuCAYAAAC7f2QuAAAgAElEQVR4nOy9XUhjWbo3vu72RRgkF5

  9. UVA 10564 Paths through the Hourglass[DP 打印]

    UVA - 10564 Paths through the Hourglass 题意: 要求从第一层走到最下面一层,只能往左下或右下走 问有多少条路径之和刚好等于S? 如果有的话,输出字典序最小的路径 ...

随机推荐

  1. Python读取Excel数据

    今天一同学给我发来一个Excel文件,让我帮他找一些信息,打开一开 8000多条数据.自己手工处理是不可能完成的的啦.作为一名程序员,当然要用程序来处理.处理生活中的问题当然是Python最为方便啦. ...

  2. Android SharedPreferences登录记住密码

    SharedPreferences是Android中存储简单数据的一个工具类.可以想象它是一个小小的Cookie,它通过用键值对的方式把简单 数据类型(boolean.int.float.long和S ...

  3. UVa 10837 A Research Problem 欧拉函数

    题意: 给你一个欧拉函数值 phi(n),问最小的n是多少. phi(n) <= 100000000 , n <= 200000000 解题思路: 对于欧拉函数值可以写成 这里的k有可能是 ...

  4. BZOJ 1025 [SCOI2009]游戏

    1025: [SCOI2009]游戏 Time Limit: 1 Sec  Memory Limit: 162 MBSubmit: 1533  Solved: 964[Submit][Status][ ...

  5. 【中国剩余定理】【容斥原理】【快速乘法】【数论】HDU 5768 Lucky7

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5768 题目大意: T组数据,求L~R中满足:1.是7的倍数,2.对n个素数有 %pi!=ai  的数 ...

  6. 【数学】XMU 1593 找数字

    题目链接: http://acm.xmu.edu.cn/JudgeOnline/problem.php?id=1593 题目大意: T组数据,n个数,只有一种出现q次,其余的出现p次.(1<=T ...

  7. 9. memcpy() memccpy() memmove() strcpy() memset()

    部分参考: http://www.cppblog.com/kang/archive/2009/04/05/78984.html 表头文件: #include <string.h>定义函数: ...

  8. [Java] 类的初始化步骤

    前言 类的初始化过程,可在多线程环境下进行的,为了简化,本文介绍的单线程情况下的类初始化步骤. 此外,继承情况下的顺序不是本文焦点,本文重点在于一个类的内部字段的初始化顺序.想了解继承情况下的初始化情 ...

  9. Maven搭建环境(Linux& Windows)

    Linux下安装Maven 1.前提条件: 1)下载并安装好JDK .在终端输入命令“java -version”,如果出现类似如下信息说明JDK安装成功. $ java -version java ...

  10. C#中枚举类型和int类型的转化

    先定义一个枚举类型 , 初中, 高中,大学 }; int ->enum int d=2; PropertyType  a=(PropertyType)d; int <- enum Prop ...