| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 3233 人关注过本帖
标题:[求助]ACM练习题目
只看楼主 加入收藏
企鹅
Rank: 1
等 级:新手上路
帖 子:93
专家分:0
注 册:2006-7-14
收藏
 问题点数:0 回复次数:21 
[求助]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: 9Rank: 9Rank: 9
等 级:贵宾
威 望:59
帖 子:3872
专家分:684
注 册:2006-10-13
收藏
得分:0 
有没有中文

My Blog: www.aiexp.info
虽然我的路是从这里开始的,但是这里不再是乐土.感谢曾经影响过,引导过,帮助过我的董凯,飞燕,leeco,starwing,Rockcarry,soft_wind等等等等.别了,BCCN.
2007-08-07 08:01
企鹅
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
cwande
Rank: 2
等 级:新手上路
威 望:3
帖 子:333
专家分:0
注 册:2006-8-18
收藏
得分:0 
排序吧........

汗,都懒得写代码了.......... cheat了一个威望,哈.....
2007-08-07 13:32
卧龙孔明
Rank: 9Rank: 9Rank: 9
等 级:贵宾
威 望:59
帖 子:3872
专家分:684
注 册:2006-10-13
收藏
得分:0 
以前有这道题的讨论,你可以在C区找到

My Blog: www.aiexp.info
虽然我的路是从这里开始的,但是这里不再是乐土.感谢曾经影响过,引导过,帮助过我的董凯,飞燕,leeco,starwing,Rockcarry,soft_wind等等等等.别了,BCCN.
2007-08-07 18:45
wingyip
Rank: 1
等 级:新手上路
威 望:2
帖 子:119
专家分:0
注 册:2007-7-16
收藏
得分:0 
#include<iostream>
#include<string>
using namespace std;
typedef struct phone
{
string data;
struct phone *next;
}node;
char change(char one)
{
if(one>='A'&&one<='Z')
{
switch(one)
{
case 'A':
case 'B':
case 'C':
return '2';
break;
case 'D':
case 'E':
case 'F':
return '3';
break;
case 'G':
case 'H':
case 'I':
return '4';
break;
case 'J':
case 'K':
case 'L':
return '5';
break;
case 'M':
case 'N':
case 'O':
return '6';
break;
case 'P':
case 'R':
case 'S':
return '7';
break;
case 'T':
case 'U':
case 'V':
return '8';
break;
case 'W':
case 'X':
case 'Y':
return '9';
break;
}
}
else return one;
}
main()
{
node *head,*pre,*p,*q;
int x,y,z,i,k;
string temp1,temp2;
cout<<"enter a number"<<endl;
cin >>x;
head=new node;
pre=head;
for(i=0;i<x;i++)
{
cin >>temp1;
y=temp1.length();
k=0;
temp2="";
for(z=0;z<y;z++)
{
if(k==3)
{
temp2=temp2+'-';
k++;
}
if(temp1[z]!='-')
{
temp2=temp2+change(temp1[z]);
k++;
}
}
p=new node;
p->data=temp2;
pre->next=p;
pre=pre->next;
}
pre->next=NULL;
cout<<endl<<endl;
pre=head->next;
while(pre!=NULL)
{
temp1=pre->data;
p=pre->next;
q=pre;
k=1;
while(p!=NULL)
{
if(temp1==p->data)
{
k++;
q->next=p->next;
delete(p);
p=q->next;
}
else
{
p=p->next;
q=q->next;
}
}
if(k>1)
cout<<temp1<<" "<<k<<endl;
pre=pre->next;
}
return 0;
}





這個是我的做法。樓主你試試會不會超時?

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

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

2007-08-16 17:06
wingyip
Rank: 1
等 级:新手上路
威 望:2
帖 子:119
专家分:0
注 册:2007-7-16
收藏
得分:0 
什么意思?
什么‘-’沒有?

2007-08-16 17:52
企鹅
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
wingyip
Rank: 1
等 级:新手上路
威 望:2
帖 子:119
专家分:0
注 册:2007-7-16
收藏
得分:0 
那我再試試排序看。

2007-08-17 06:43
快速回复:[求助]ACM练习题目
数据加载中...
 
   



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

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