标题:[求助]ACM练习题目
取消只看楼主
企鹅
Rank: 1
等 级:新手上路
帖 子:93
专家分:0
注 册:2006-7-14
 问题点数:0 回复次数:4 
[求助]ACM练习题目

487-3279
Time Limit:2000MS Memory Limit:30000K
Total Submit:50585 Accepted:8679

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
我写的程序
#include <string>
#include <iostream>
using namespace std;
struct tele
{
string number;
long time;
};

int main()
{
string temp,temp1;
long i,l=0,length=0,m;
int j,k;
cin>>i;
tele *p;
p=new tele[50000];
while(l<i)
{
j=0;
k=0;
cin >>temp;
while(j<7)
{
switch(temp[k++])
{
case '0':temp1+="0";j++;break;
case '1':temp1+="1";j++;break;
case 'A':
case 'B':
case 'C':
case '2':temp1+="2";j++;break;
case 'D':
case 'E':
case 'F':
case '3':temp1+="3";j++;break;
case 'G':
case 'H':
case 'I':
case '4':temp1+="4";j++;break;
case 'J':
case 'K':
case 'L':
case '5':temp1+="5";j++;break;
case 'M':
case 'N':
case 'O':
case '6':temp1+="6";j++;break;
case 'P':
case 'R':
case 'S':
case '7':temp1+="7";j++;break;
case 'T':
case 'U':
case 'V':
case '8':temp1+="8";j++;break;
case 'W':
case 'X':
case 'Y':
case '9':temp1+="9";j++;break;
}
}
for(m=0;m<length;m++)
{
if(p[m].number==temp1)
{
p[m].time++;
break;
}
}
if(m==length)
{
p[m].number=temp1;
p[m].time=1;
length++;
}
temp1="";
l++;
}
long mix;
for(l=0;l<length-1;l++)
{
mix=l;
for(i=l+1;i<length;i++)
{
if(p[mix].number>p[i].number)
mix=i;
}
if(mix!=l)
{
temp1=p[l].number;
p[l].number=p[mix].number;
p[mix].number=temp1;
m=p[l].time;
p[l].time=p[mix].time;
p[mix].time=m;
}
}
for(l=0;l<length;l++)
{
if(p[l].time==1)
continue;
for(j=0;j<3;j++)
cout<<p[l].number[j];
cout<<"-";
for(;j<7;j++)
cout<<p[l].number[j];
cout<<" "<<p[l].time;
cout<<endl;
}
return 0;
}
结果超时了.希望高手指导.不必代码.说说想法即可

搜索更多相关主题的帖子: ACM 练习 题目 memorable spell 
2007-08-07 05:35
企鹅
Rank: 1
等 级:新手上路
帖 子:93
专家分:0
注 册:2006-7-14
得分:0 

企业总希望有难以忘记的电话号码。一种使电话号码难以忘记的方法是将其用难以忘记的单词或词组来拼写。例如,你可以拨这个好记的电话号码:TUT-GLOP来给滑铁卢大学打电话。有些时候,一个电话号码只有部分被拼成单词。今晚你回到你的旅馆后,你可以打电话:310-GINO到Gino比萨店定比萨。另一种使电话号码好记的方法是将数字组合成好记的形式。你可以打“三十电话”3-10-10-10到必胜客定比萨。

电话号码的标准形式是七位数,并且第三个数与第四个数之间有一个连字符(例如:888-1200)。电话上的按键提供了字母与数字的影射,如下:

A,B,和C对应2

D,E,和F对应3

G,H,和I对应4

J,K,和L对应5

M,N,和O对应6

P,R,和S对应7

T,U,和V对应8

W,X,和Y对应9

没有数字与Q或Z对应。连字符不需要拨,而且可以根据需要添加或删除。TUT-GLOP的标准形式是888-4567。310-GINO的标准形式是310-4466。3-10-10-10的标准形式是310-1010。

当两个电话号码拥有相同的标准形式时,这两个电话号码是一样的。(它们拨相同的号码。)

你的公司正在搜集本地的企业的电话号码。对于其中的一部分进程,你将检查其中是否有两个(或更多)的电话号码相同。

输入
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

输入文件将会包含一组测试数据。第一行有一个整数,表示电话号码簿中的电话号码的数量(不大于100,000)。接下来每行列出了一个字符串,表示电话号码。每一个电话号码中一定有且只有七个大写字母(不包括Q,Z)或数字。

输出

为每一个出现过多次的电话号码生成一行。这一行内应包括这个电话号码的标准形式和出现的次数,中间用一个空格隔开。所有的电话号码应以字典次序升序排列。如果没有任意两个电话号码相同,输出:


2007-08-07 11:05
企鹅
Rank: 1
等 级:新手上路
帖 子:93
专家分:0
注 册:2006-7-14
得分:0 

你输出的"-"没有吧.去试了一下 WA了

2007-08-16 17:06
企鹅
Rank: 1
等 级:新手上路
帖 子:93
专家分:0
注 册:2006-7-14
得分:0 

对不起,看错了啊,你多了一句话cout<<"enter a number"<<endl;
还有结果要排序的,你没有排.还是WA了.不过还是很感谢你.


310-1010 2
487-3279 4
888-4567 3
是按号码的大小排的

[此贴子已经被作者于2007-8-17 5:49:21编辑过]

2007-08-17 05:48
企鹅
Rank: 1
等 级:新手上路
帖 子:93
专家分:0
注 册:2006-7-14
得分:0 
不知道为何。你的答案又WA了
这里是这个问题的地址http://acm.pku.edu.cn/JudgeOnline/submit?problem_id=1002
楼主你可以自己去试看看。
你对问题的直琢实在领人佩服。
我是个初学者。交个朋友吧。qq:53988704
2007-08-19 04:55



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-160833-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.394234 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved