#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. 转:Hprose for php(二)——服务器

    文章来自于:http://blog.csdn.net/half1/article/details/21252879 本文将介绍Hprose for php服务器的更多细节 1.发布服务 Hprose提 ...

  2. asp.net请求流程

    http://developer.51cto.com/art/200902/109441.htm http://www.cnblogs.com/couhujia/archive/2010/04/21/ ...

  3. Android调用Asp.net Web Service示例

    WebService代码: using System; using System.Collections.Generic; using System.Linq; using System.Web; u ...

  4. H.264 Quantization

    H.264 Quantizer 一般的量化器,可用下面的公式来表示: $Z=\pm \left \lfloor\frac{ \left | W \right | }{\bigtriangleup }\ ...

  5. 如何删除windows服务(sc.exe删除和注册表删除两种方法)

    一.什么是Windows服务 Windows服务也称为Windows Service,它是Windows操作系统和Windows网络的基础,属于系统核心的一部分,它支持着整个Windows的各种操作. ...

  6. COJN 0486 800401反质数 呵呵呵呵呵

    800401反质数 难度级别:A: 运行时间限制:1000ms: 运行空间限制:51200KB: 代码长度限制:2000000B 试题描述 将正整数 x 的约数个数表示为 g(x).例如,g(1)=1 ...

  7. HttpURLConnection和HttpClient

    HTTP 协议可能是现在 Internet 上使用得最多.最重要的协议了,越来越多的 Java 应用程序需要直接通过 HTTP 协议来访问网络资源.在 JDK 的 java.net 包中已经提供了访问 ...

  8. tomcat : Error configuring application listener of class org.springframework.web.context.ContextLoaderListener java.lang.ClassNotFoundException:

    错误 严重: Error configuring application listener of class org.springframework.web.context.ContextLoader ...

  9. 终于有人把O2O、C2C、B2B、B2C的区别讲透了

    一.O2O.C2C.B2B.B2C的区别在哪里? o2o 是 online to offline 分为四种运营模式 1.online to offline 是线上交易到线下消费体验 2.offline ...

  10. 第1章 Python介绍

    本章将包含Python的介绍,安装以及Python的数据类型及运算符.其中关于数据类型中的字符串.列表.元组和字典后续章节会着重介绍. 1.1 为什么学Python Python是一门简明并强大的面向 ...