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,并且 ...
随机推荐
- PHP网站 通过js方式判断是否是手机访问,若是 跳转到手机版网址!
<script type="text/javascript" src="http://i3.dukuai.com/ui/js/jquery-1.32pack.js& ...
- 363 Max Sum of Rectangle No Larger Than K 最大矩阵和不超过K
Given a non-empty 2D matrix matrix and an integer k, find the max sum of a rectangle in the matrix s ...
- 357 Count Numbers with Unique Digits 计算各个位数不同的数字个数
给定一个非负整数 n,计算各位数字都不同的数字 x 的个数,其中 0 ≤ x < 10n.示例:给定 n = 2,返回 91.(答案应该是除[11,22,33,44,55,66,77,88,99 ...
- 深入Mysql字符集设置
作者: Laruence( ) 本文地址: http://www.laruence.com/2008/01/05/12.html 转载请注明出处 根据Chaos Wang的PPT整理而成, 在此 ...
- Xml的读取
using System; using System.Collections.Generic; using System.Linq; using System.Web; namespace WebAp ...
- input获得焦点和失去焦点
总结:placeholder因为在IE7 8 9 浏览器不支持所以没用它效果:当input获取光标的时候如果是默认提示则input内容为空.如果不是则为输入内容 当失去光标的时候, ...
- 通过yum命令搭建lamp环境(centos6.5)
centos 6.5 1.yum安装和源代码编译在使用的时候没啥区别,但是安装的过程就大相径庭了,yum只需要3个命令就可以完成,源代码需要13个包,还得加压编译,步骤很麻烦,而且当做有时候会出错,源 ...
- JS——模拟百度搜索
注意事项: 1.for循环移除子节点时,其长度是变化的 2.在文档流中,input.img.p等标签与其他标签有3px的距离,利用左浮动,可以消除3px距离 3.背景图片定位时,第一个值是x轴方向的值 ...
- Java_Web三大框架之Hibernate增删改查
下面介绍一下Hibernate的增删改查. 第一步:编写用户实体类以及User.hbm.xml映射 package com.msl.entity; public class User { privat ...
- 13、scala模式匹配
1.模式匹配的基础语法 2.对类型进行模式匹配 3.对Array和List的元素进行模式匹配 4.case class与模式匹配 5.Option与模式匹配 1.模式匹配的基础语法 Scala提供了m ...