PKU OJ 1002 487-3279

487-3279

Description

Businesses like to have memorable telephone numbers. One way to make a telephone number memorable is to have it spell a memorable word or phrase. For example, you can call the University of Waterloo by dialing the memorable TUT-GLOP. Sometimes only part of the number is used to spell a word. When you get back to your hotel tonight you can order a pizza from Gino's by dialing 310-GINO. Another way to make a telephone number memorable is to group the digits in a memorable way. You could order your pizza from Pizza Hut by calling their "three tens" number 3-10-10-10.

The standard form of a telephone number is seven decimal digits with a hyphen between the third and fourth digits (e.g. 888-1200). The keypad of a phone supplies the mapping of letters to numbers, as follows:

A, B, and C map to 2

D, E, and F map to 3

G, H, and I map to 4

J, K, and L map to 5

M, N, and O map to 6

P, R, and S map to 7

T, U, and V map to 8

W, X, and Y map to 9

There is no mapping for Q or Z. Hyphens are not dialed, and can be added and removed as necessary. The standard form of TUT-GLOP is 888-4567, the standard form of 310-GINO is 310-4466, and the standard form of 3-10-10-10 is 310-1010.

Two telephone numbers are equivalent if they have the same standard form. (They dial the same number.)

Your company is compiling a directory of telephone numbers from local businesses. As part of the quality control process you want to check that no two (or more) businesses in the directory have the same telephone number.

Input

The input will consist of one case. The first line of the input specifies the number of telephone numbers in the directory (up to 100,000) as a positive integer alone on the line. The remaining lines list the telephone numbers in the directory, with each number alone on a line. Each telephone number consists of a string composed of decimal digits, uppercase letters (excluding Q and Z) and hyphens. Exactly seven of the characters in the string will be digits or letters.

Output

Generate a line of output for each telephone number that appears more than once in any form. The line should give the telephone number in standard form, followed by a space, followed by the number of times the telephone number appears in the directory. Arrange the output lines by telephone number in ascending lexicographical order. If there are no duplicates in the input print the line:

No duplicates.

Sample Input

12

4873279

ITS-EASY

888-4567

3-10-10-10

888-GLOP

TUT-GLOP

967-11-11

310-GINO

F101010

888-1200

-4-8-7-3-2-7-9-

487-3279

Sample Output

310-1010 2

487-3279 4

888-4567 3

Source

East Central North America 1999

(1)其实我的思路没啥错的,将输入的字符串转换为整数int,存在数组中,因为号码之后七位数所以这样考虑是对的,而且之后看到别人的答案大部分都觉得字符串排序处理起来比较慢;

(2)在排序这块想到的是用比较快的排序来算,从网上摘抄了一段快速排序的源码来用,结果还是超时了,于是用C++里面自带的一个qsort来排序,还写了一个比较函数;

(3)之前有个错误一直没有发现,导致多次提交心里很是蛋疼,你说做OJ这种东西,明明感觉是到处都对,感觉练到手就好了,但是还是希望最后能够AC的。一次次提交失败让我很是不爽啊;心一横去网上找测试数据;居然找到了;

(4)找到了然后又要把数据一个个读出来,又是一番百度;

(5)结果通过对比测试的数据,发现数字和大写字母的对应搞错了一个,结果改了一个符号就AC,唉;

(5)搞OJ还学会了不少新词呢,什么WA,RE还有AC的,当然大家是都想要AC的啦;

(6)很多人呢这题也没有通过,然后就是贴代码,我也想贴啊,让人绑我看看那儿错了,但是大牛们谁会帮你看代码呢,有病还是自己治,这里捅捅,那里捅捅说不定就成了呢;

(7)主要是为了学C++,各种强行面向对象,有啥高级货都拿来试试,关键是还没学到STL和更高级的东东,有所限制。

 #include <iostream>

 #include <stdio.h>

 using namespace std;

 class Phone {

     int table[];

     int total;

     int collect[];

     int flag;

 public:

     Phone(int T) {

         total = T;

         for(int i=; i<T; i++)    //将表初始化

             table[i]=;

     }

     void TurnOver(char* s,int n) {

         int p=, pow=,flag=,m;

         for(int i=; i<; i++)

         {

             if(flag >= )

                 break;

             switch (s[i]) {

                 case '': {m=;p=;break;}

                 case '': {m=;p=;break;}

                 case '': case 'A': case 'B': case 'C': {m=;p=;break;}

                 case '': case 'D': case 'E': case 'F': {m=;p=;break;}

                 case '': case 'G': case 'H': case 'I': {m=;p=;break;}

                 case '': case 'J': case 'K': case 'L': {m=;p=;break;}

                 case '': case 'M': case 'N': case 'O': {m=;p=;break;}

                 case '': case 'P': case 'R': case 'S': {m=;p=;break;}

                 case '': case 'T': case 'U': case 'V': {m=;p=;break;}

                 case '': case 'X': case 'Y': case 'W': {m=;p=;break;}

             }

             if(p==) {

                 flag++;

                 table[n] += m*pow;

                 pow /= ;

                 p=;

             }

         }

     }

     void printPhone() {

         int a;

         int pow;

         int temp;

         if(flag==) {

             cout << "No duplicates." << endl;

             return;

         }

         for(int i=; i<total; i++) {

             if(collect[i]>=) {

                 temp = table[i];

                 //这里输出电话号码时,注意不能动table

                 pow = ;

                 for(int j=; j<; j++) {

                     a = temp/pow;

                     temp = temp - a*pow;

                     pow = pow/;

                     cout << a;

                     if(j==)

                         cout << "-";

                 }

                 cout << " " << collect[i]+ << endl;

             }

         }

     }

     void quickSort(int s[], int l, int r) {

         if(l<r) {

             int i=l, j=r, x=s[l];

             while (i<j) {

                 while(i<j && s[j]>=x)

                     j--;

                 if(i<j)

                     s[i++] = s[j];

                 while(i<j && s[i]<x)

                     i++;

                 if(i<j)

                     s[j--] = s[i];

             }

             s[i]=x;

             quickSort(s, l, i-);

             quickSort(s, i+, r);            

         }

     }

     void Sort() {

         quickSort(table,,total-);

     }

     void dupSelect() {

         int tmp = table[],pos=;

         flag=;

         for(int i=; i<total; i++)

             collect[i]=;

         for(int i=; i<total; i++) {

             if (tmp == table[i]) {

                     collect[pos]++;

                     flag=;

             }

             else {

                 tmp = table[i];

                 pos=i;

             }

         }

     }    

 };

 int main(void) {

     int T;

     char s[];

     cin >> T;

     getchar();

     Phone a(T);

     for(int i=; i<T; i++) {

         gets(s);

         a.TurnOver(s, i);

     }

     a.Sort();

     a.dupSelect();

     a.printPhone();

 }

PKU OJ 1002 487-3279的更多相关文章

  1. 九度OJ 1002:Grading

    时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:18410 解决:4753 题目描述: Grading hundreds of thousands of Graduate Entrance ...

  2. Light oj 1002 Country Roads (Dijkstra)

    题目连接: http://www.lightoj.com/volume_showproblem.php?problem=1002 题目描述: 有n个城市,从0到n-1开始编号,n个城市之间有m条边,中 ...

  3. OJ#1002 又是a+b

    题目描述: 给定两个正整数a.b(0 < a,b < =10000),求出a+b的和 输入描述: 多组输入,每组输入为一行,里面有2个数a,b(0 < a,b < =10000 ...

  4. pku oj overhang叠加卡片求最少的卡片数

    这个估计是里面第二简单的了,因为第一简单的是求a+b 哈哈,一submit就ac了 题目如下: Description How far can you make a stack of cards ov ...

  5. PKU OJ Exponentiation

    ExponentiationTime Limit: 500MS                      Memory Limit: 10000KTotal Submissions: 155886   ...

  6. oj 1002题 (大数题)

    #include <stdio.h> #include <string.h> int main(void) { int q,j,h,k,l; int d; ],s2[];//题 ...

  7. 九度oj 1002 Grading 2011年浙江大学计算机及软件工程研究生机试真题

    #include<iostream> #include<queue> #include<cstdio> #include<cstring> #inclu ...

  8. 杭电oj 1002

    #include <iostream> #include <algorithm> using namespace std; int nCases; ], n[]; ], b[] ...

  9. PKU OJ A Bug's life

    http://bailian.openjudge.cn/tm2018/G/ #include <iostream> #include <vector> #include < ...

随机推荐

  1. CSS:关于CSS Hack

    CSS Hack由于不同厂商的浏览器,如Internet Explorer,Safari,Mozilla Firefox,Chrome 等,或者是同一厂商的浏览器的不同版本,如IE6和IE7,对CSS ...

  2. 批量修改Java类文件中引入的package包路径

    http://libeey.blogbus.com/logs/101848958.html当复制其他工程中的包到新工程的目录中时,由于包路径不同,出现红叉,下面的类要一个一个修改包路径,类文件太多的话 ...

  3. PowerDesigner 表模型图展示列信息

    今天突然发现表模型不展示列信息了,只显示一个名称,如下图:     虽让点击表模型能看到,但我想让他本身就显示,pd默认就是会显示的,今天不知怎么了,网上找这方面的设置很难找,所以我记录下设置方法(我 ...

  4. [Python]网络爬虫(五):urllib2的使用细节与抓站技巧(转)

    1.Proxy 的设置 urllib2 默认会使用环境变量 http_proxy 来设置 HTTP Proxy. 如果想在程序中明确控制 Proxy 而不受环境变量的影响,可以使用代理. 新建test ...

  5. 解决修改计算机名后tfs连接不上的错误

    1,用vs 自带的工具命令 tf workspaces 查看集合 2,执行命令: >tf workspaces /collection:https://aaaa.visualstudio.com ...

  6. SQL Server 2005/2008遍历所有表更新统计信息

    DECLARE UpdateStatisticsTables CURSOR READ_ONLY FOR 02   SELECT sst.name, 03          Schema_name(ss ...

  7. RHCE7 管理I-12归档文件并在Linux系统间复制文件

    tar命令使用 默认tar只有归档的功能,没有压缩功能 tar [option...] [file]... -c,--create     创建 -x,--extract,--get   解压 -t, ...

  8. Unix域套接字简介

    在Linux系统中,有很多进程间通信方式,套接字(Socket)就是其中的一种.但传统的套接字的用法都是基于TCP/IP协议栈的,需要指定IP地址.如果不同主机上的两个进程进行通信,当然这样做没什么问 ...

  9. Python isspace() 方法

    描述 Python isspace() 方法检测字符串是否只由空格组成. 语法 isspace() 方法语法: S.isspace() 参数 无. 返回值 如果字符串中至少有一个字符,并且所有字符都是 ...

  10. Aixs2 使用总结,持续更新中 ...

    参考博客:http://zhangjunhd.blog.51cto.com/113473/23692     消息交换模式. 目前Axis2支持三种模式:In-Only.Robust-In和In-Ou ...