#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. 托管host

    托管在googlecode的host https://smarthosts.googlecode.com/svn/trunk/hosts

  2. Web应用指纹识别

    http://danqingdani.blog.163.com/blog/static/186094195201493121834603/

  3. hdu 4545 魔法串

    http://acm.hdu.edu.cn/showproblem.php?pid=4545 #include <cstdio> #include <cstring> #inc ...

  4. COJ 0580 4021征兵方案

    4021征兵方案 难度级别: C: 编程语言:不限:运行时间限制:1000ms: 运行空间限制:51200KB: 代码长度限制:2000000B 试题描述 现在需要征募女兵N人,男兵M人,每征募一个人 ...

  5. 用SQL求1到N的质数和

    今天在百度知道中,遇到了一位朋友求助:利用sql求1到1000的质数和.再说今天周五下午比较悠闲,我就在MSSQL 2008中写了出来,现在分享在博客中,下面直接贴代码: declare @num i ...

  6. 动态规划初级练习(二):BadNeighbors

    Problem Statement      The old song declares "Go ahead and hate your neighbor", and the re ...

  7. libvirt hypervisors信息采集

    libvirt采集hypervisors信息的通用格式 driver[+transport]://[username@][hostname][:port]/[path][?extraparameter ...

  8. 更改navigationController push和pop界面切换动画

    For Push: MainView *nextView=[[MainView alloc] init]; [UIView beginAnimations:nil context:NULL]; [UI ...

  9. Lecture Halls

    Lecture Halls (会议安排)   时间限制(普通/Java):1000MS/10000MS     运行内存限制:65536KByte 总提交: 38            测试通过: 2 ...

  10. 从零开始写一个Tomcat(壹)

    Tomcat是一个免费的开放源代码的Web 应用服务器,属于轻量级应用服务器,也是一个servlet容器的优秀解决方案,做Java web开发的基本上都使用过,但是tomcat大多时间对于我们是一个黑 ...