一道ACM题目5036 Match WordsTimeLimit : 1 Second Memorylimit : 32 Megabyte Totalsubmit : 273 Accepted : 49xiaoz wants to remember more words.So he asks you ,as a member of a development team for a words-matching program,to write a module tha

来源:学生作业帮助网 编辑:作业帮 时间:2024/04/29 23:26:55
一道ACM题目5036 Match WordsTimeLimit : 1 Second   Memorylimit : 32 Megabyte   Totalsubmit : 273   Accepted : 49xiaoz wants to remember more words.So he asks you ,as a member of a development team for a words-matching program,to write a module tha

一道ACM题目5036 Match WordsTimeLimit : 1 Second Memorylimit : 32 Megabyte Totalsubmit : 273 Accepted : 49xiaoz wants to remember more words.So he asks you ,as a member of a development team for a words-matching program,to write a module tha
一道ACM题目
5036 Match WordsTimeLimit : 1 Second Memorylimit : 32 Megabyte
Totalsubmit : 273 Accepted : 49
xiaoz wants to remember more words.So he asks you ,as a member of a development team for a words-matching program,
to write a module that will check if a given word can match some words of a known dictionary. The dictionary is
made of words.A word w matchs a word v if and only if there is some permutation p of character positions that
takes w to v.For example,"caret" can match "cater",but "caret" can't match "certe".
Input
The first part of the input contains all words from the dictionary. Each word occupies its own line. This part is
finished by the single character '#' on a separate line. All words are different. There will be at most 20000 words
in the dictionary.
The next part of the file contains all words that are to be checked. Each word occupies its own line. This part is
also finished by the single character '#' on a separate line. There will be at most 2000 words that are to be checked.
All words in the input (words from the dictionary and words to be checked) consist only of small alphabetic characters
and each one contains 30 characters at most.
Output
Write to the output exactly one line for every checked word in the order of their appearance in the second part of the
input file.Write the checked word first,then write the character ':',and after a signle space write all its possible
words ,from the dictionary,which can match the checked word.The matching words should be written in alphabetical order.
If there are no matching words for the checked word then the line feed should immediately follow the colon.
Sample Input
undisplayed
trace
tea
singleton
eta
eat
displayed
crate
cater
carte
caret
beta
beat
bate
ate
abet
#
retac
btae
good
displayde
hello
#
Sample Output
retac: caret carte cater crate trace .
btae: abet bate beat beta .
good:
displayde:displayed .
hello:
我的思路是先读入字典中的字符串,存起来.然后再读入用来检查的字符串,存起来.然后,将字典中的字符串和用来检查的字符串分别按字母排序后形成新的字符串.然后根据新形成的用来检查的字符串一个一个地与新形成的字典中的字符串比较,若相同则保存,不相同则忽略.
最后将比较后相同的字符串用一个冒泡排序进行排序.然后按题目要求输出.
输出格式没有问题,但是超时,谁知道应该在哪个地方进行优化啊?

一道ACM题目5036 Match WordsTimeLimit : 1 Second Memorylimit : 32 Megabyte Totalsubmit : 273 Accepted : 49xiaoz wants to remember more words.So he asks you ,as a member of a development team for a words-matching program,to write a module tha
哈工程上的题目?
做的时间有点长了,忘记了,不过代码还在.
#include
using namespace std;
char a[20002][31],b[20002][31];
int n;
struct Node
{
char *pa,*pb;
}c[20002];
bool cmp(Node x,Node y)
{
int t = strcmp(x.pb,y.pb);
if( t ) return t < 0;
return strcmp (x.pa,y.pa) < 0;
}
int search(char *s)
{
int left = 0,right = n-1,mid;
while( left 0) left = mid + 1;
else right = mid - 1;
}
return -1;
}
int main()
{
int i = 0;;
while(scanf( "%s",a[i]) ,a[i][0] != '#')
{
strcpy(b[i],a[i]);
sort(b[i],b[i]+strlen(b[i]));
c[i].pa = a[i];
c[i].pb = b[i];
i++;
}
n = i;
sort(c,c+n,cmp);
char s[31];
while(scanf("%s",s),s[0] != '#')
{
printf("%s:",s);
sort(s,s+strlen(s));
int t = search(s);
if( t == -1 )
{
putchar('\n');
continue;
}
putchar(' ');
while(t>0 && strcmp(c[t-1].pb,c[t].pb) == 0 ) t--;
do
{
printf("%s ",c[t].pa);
t++;
}while(t

一道ACM题目5036 Match WordsTimeLimit : 1 Second Memorylimit : 32 Megabyte Totalsubmit : 273 Accepted : 49xiaoz wants to remember more words.So he asks you ,as a member of a development team for a words-matching program,to write a module tha acm stars题目意思是什么 wo won the football match a_____ that team yesterday 一道ACM题目,麻烦帮我解释下题意举个例子帮我说明下题意 求助一道ACM题一道很简单的ACM题目,题在这里我写的代码如下:#include using namespace std;int main(){int n,m[30];cin>>n;for(int i=0;i=0;j--){cout acm的一道c语言问题 【求助】北大acm JudgeOnline 请问谁有用C语言编写的北大acm JudgeOnline上面的题目的代码?不要求全不要有,poj1094、poj1125、poj1251、poj1915、poj1979有这五道题最好,或者一道都行啊(提供个链接都行) 问你一道题,【题目如下】,好像是连线题Think and match【作业题目】sweet 醋 盐 freshhealyhy apple chicken tastysour 糖 fish saltyThink and match【作业题目】sweet 醋 盐 freshhealthy apple chicken tastysour 糖 fish salty wo 一道acm的排序题Snow_storm有n(0 一道ACM 数字统计 描述:给出一个整数n(1 英文(ACM题目)的中文翻译去哪找最好! 求解ACM题目孪生素数请用C++代码 有关ACM一道题,你的任务是计算a+b.这是为了acm初学者专门设计的题目.你肯定发现还有其他题目跟这道题的标题类似,这些问题也都是专门为初学者提供的.输入格式输入包含一系列的a和b对,通 Match match ... acm 一道水题:Increase and Decrease 求思路DescriptionPolycarpus has an array, consisting of n integers a1, a2, ..., an. Polycarpus likes it when numbers in an array match. That's why he wants the array to have as many eq 一道ACM题目(解释一下题意)http://acm.hrbeu.edu.cn/index.php?act=problem&proid=6060主要是这段话不理解:Factorials grow very rapidly--5! = 120, 10! = 3,628,800. One way of specifying such large numbers is by specifying the number of