UVa 642 - Word Amalgamation
题目:给你一个单词列表。再给你一些新的单词。输出列表中又一次排列能得到此新单词的词。
分析:字符串。对每一个字符串的字母排序生成新的传f(str)。总体排序,用二分来查找就可以。
说明:注意输出要满足字典序,先排序后查找。
#include <algorithm>
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <cstdio> using namespace std; typedef struct wnode
{
char word[7];
char abcd[7];
}words;
words W[101]; int cmp(words a, words b)
{
int c = strcmp(a.abcd, b.abcd);
if (c != 0) return c<0;
return strcmp(a.word, b.word)<0;
} int bs(char str[], int r)
{
int l = 0,m,c;
while (l < r) {
m = (l+r)/2;
c = strcmp(W[m].abcd, str);
if (c < 0)
l = m+1;
else r = m;
}
return l;
} char buf[7]; int main()
{
int count = 0;
while (gets(W[count].word) && strcmp(W[count].word, "XXXXXX")) {
strcpy(W[count].abcd, W[count].word);
sort(W[count].abcd, W[count].abcd+strlen(W[count].abcd));
count ++;
} sort(W, W+count, cmp); while (gets(buf) && strcmp(buf, "XXXXXX")) {
sort(buf, buf+strlen(buf));
int s = bs(buf, count-1),flag = 0;
while (!strcmp(buf, W[s].abcd)) {
printf("%s\n",W[s ++].word);
flag = 1;
}
if (!flag)
printf("NOT A VALID WORD\n");
printf("******\n");
}
return 0;
}
UVa 642 - Word Amalgamation的更多相关文章
- Uva 642 - Word Amalgamation sort qsort
Word Amalgamation In millions of newspapers across the United States there is a word game called J ...
- Word Amalgamation(枚举 + 排序)
Word Amalgamation Time Limit: 1 Sec Memory Limit: 64 MB Submit: 373 Solved: 247 Description In mil ...
- hdu-----(1113)Word Amalgamation(字符串排序)
Word Amalgamation Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others ...
- Word Amalgamation(hdoj1113)
Word Amalgamation Problem Description In millions of newspapers across the United States there is a ...
- hdu1113 Word Amalgamation(详解--map和string的运用)
版权声明:本文为博主原创文章.未经博主同意不得转载. vasttian https://blog.csdn.net/u012860063/article/details/35338617 转载请注明出 ...
- HDOJ.1113 Word Amalgamation(map)
Word Amalgamation 点我挑战题目 点我一起学习STL-MAP 题意分析 给出字典.之后给出一系列======乱序======单词,要求你查字典,如过这个乱序单词对用有多个有序单词可以输 ...
- poj1318 Word Amalgamation 字符串排序(qsort)
Word Amalgamation Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 9794 Accepted: 4701 ...
- poj 1318 Word Amalgamation
Word Amalgamation Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 9968 Accepted: 4774 ...
- hdu 1113 Word Amalgamation 解题报告
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1113 题意:输入一个字典,然后再输入若干单词(每行中,1 <= 单词数 <= 100,并且 ...
随机推荐
- P2068 统计和
P2068 统计和 这题真的非常水了 如果不会 右转[模板]树状数组 2 基本上是一模一样的 #include <bits/stdc++.h> #define lowbit(x) x&am ...
- BZOJ 4828 DP+BFS
被一道简单BFS坑了这么长时间我也是hhh了 //By SiriusRen #include <bits/stdc++.h> using namespace std; ,,):d(D),x ...
- ansible剧本
yaml简介 YAML是"YAML Ain't a Markup Language"(YAML不是一种置标语言)的递归缩写,早先YAML的意思其实是:"Yet Anoth ...
- Unity Sprite Packer 问题集合
介绍 今天突发奇想用了下sprite packer 这个功能,基本用法网上教程一堆一堆的,这里就不赘述了. 在使用sprite packer过程中遇到一些问题,然后各种百度不到答案,最后和谐上网找到了 ...
- struts2.1.6存在中文乱码的bug
如题,后续版本中已解决:可以通过添加filter的方式解决.
- Java jre7及以上版本中的switch支持String的实现细节
Java7中的switch支持String的实现细节 作者: zsxwing 更新: 2013-03-04 21:08:02 发布: 2012-04-26 13:58:19 在Java7之前,swit ...
- 论文deadline 最后三天
2015.12.29 星期二 内容整改 2015.12.30 星期三 参考文献,摘要等 2015.12.31 星期四 最后修改 尽最大的努力去做好论文的事情.
- id拼接保存到单个字段后作为表连接的查询条件
SELECT q.id, concat(q. NAME) qname, d.id did, d. NAME FROM question_po q LEFT JOIN data_configuratio ...
- CAD类型转换
AcDbEntity *pEnt; AcDbCircle *pcir = AcDbCircle::cast(pEnt); static_cast<AcDbCircle*>(pEnt); p ...
- redis中关于使用string类型还是hash类型
前篇:最近在做一个将redis中大数据量进行合并缩减优化的工作,其中一项按月将数据进行合并.将一个月的数据放入一个key-value键值对中. 例:p2d20180901-3.p2d20180902- ...