#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. 去除win8.1这台电脑中的6个库文件夹

    HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\MyComputer\NameSpace,备份之后删除 wi ...

  2. yui--datatable基础和常用知识总结

    1.namespace 用于创建一个全局的命名空间,使用YUI时,首先会自动创建widget,util,example三个命名空间,使用时也可以自定义命名空间.类似于在程序中建了了一个static变量 ...

  3. Stm32 定时器 定时时间设置及PWM频率 占空比的设置总结

    一.定时器的时钟: 当SYSCLK等于72M,APB1等于36M APB2等于72M时,定时器的时钟为72M.注意图中这句话:如果APB1/APB2预分频器=1则频率不变,否则频率x2.如果此时,AP ...

  4. php开启错误提示

    1.在php.ini文件里加上下面两句 display_errors = Onerror_reporting = E_ALL | E_STRICT 2.在Apache的 httpd.conf文件里加上 ...

  5. 在EF中执行SQL语句

    你可能要问,我用EF不就为了避免写SQL吗?如果要写SQL我不如直接用ADO.NET得了.话虽然这么说没错,可有些时候使用EF操作数据还是有一些不方便,例如让你根据条件删除一组记录,如果按照正常的流程 ...

  6. UINavigationController 导航控制器 ,根据文档写的一些东西

    今天讲了导航控制器UINavigationController 和标签栏视图控制器UITabBarController 先来说一说导航视图控制器  UINavigationController 导航控 ...

  7. Linux shell 之 提取文件名和目录名的一些方法

    很多时候在使用Linux的shell时,我们都需要对文件名或目录名进行处理,通常的操作是由路径中提取出文件名,从路径中提取出目录名,提取文件后缀名等等.例如,从路径/dir1/dir2/file.tx ...

  8. 【高级算法】模拟退火算法解决3SAT问题(C++实现)

    转载请注明出处:http://blog.csdn.net/zhoubin1992/article/details/46453761 ---------------------------------- ...

  9. Java TCP服务端向客户端发送图片

    /** * 1.创建TCP服务端,TCP客户端 * 2.服务端等待客户端连接,客户端连接后,服务端向客户端写入图片 * 3.客户端收到后进行文件保存 * @author Administrator * ...

  10. PHP开发Android应用程序(转)

    第一部分是指在Android系统的手机上直接写PHP脚本代码并立即运行:第二部分则继续讲解如何把写好的PHP脚本代码打包成akp安装文件. 首先,在手机上安装两个apk包. 一个是SL4A(Scrip ...