题目:给你一个单词列表。再给你一些新的单词。输出列表中又一次排列能得到此新单词的词。

分析:字符串。对每一个字符串的字母排序生成新的传f(str)。总体排序,用二分来查找就可以。

说明:注意输出要满足字典序,先排序后查找。

  1. #include <algorithm>
  2. #include <iostream>
  3. #include <cstdlib>
  4. #include <cstring>
  5. #include <cstdio>
  6.  
  7. using namespace std;
  8.  
  9. typedef struct wnode
  10. {
  11. char word[7];
  12. char abcd[7];
  13. }words;
  14. words W[101];
  15.  
  16. int cmp(words a, words b)
  17. {
  18. int c = strcmp(a.abcd, b.abcd);
  19. if (c != 0) return c<0;
  20. return strcmp(a.word, b.word)<0;
  21. }
  22.  
  23. int bs(char str[], int r)
  24. {
  25. int l = 0,m,c;
  26. while (l < r) {
  27. m = (l+r)/2;
  28. c = strcmp(W[m].abcd, str);
  29. if (c < 0)
  30. l = m+1;
  31. else r = m;
  32. }
  33. return l;
  34. }
  35.  
  36. char buf[7];
  37.  
  38. int main()
  39. {
  40. int count = 0;
  41. while (gets(W[count].word) && strcmp(W[count].word, "XXXXXX")) {
  42. strcpy(W[count].abcd, W[count].word);
  43. sort(W[count].abcd, W[count].abcd+strlen(W[count].abcd));
  44. count ++;
  45. }
  46.  
  47. sort(W, W+count, cmp);
  48.  
  49. while (gets(buf) && strcmp(buf, "XXXXXX")) {
  50. sort(buf, buf+strlen(buf));
  51. int s = bs(buf, count-1),flag = 0;
  52. while (!strcmp(buf, W[s].abcd)) {
  53. printf("%s\n",W[s ++].word);
  54. flag = 1;
  55. }
  56. if (!flag)
  57. printf("NOT A VALID WORD\n");
  58. printf("******\n");
  59. }
  60. return 0;
  61. }

UVa 642 - Word Amalgamation的更多相关文章

  1. Uva 642 - Word Amalgamation sort qsort

     Word Amalgamation  In millions of newspapers across the United States there is a word game called J ...

  2. Word Amalgamation(枚举 + 排序)

    Word Amalgamation Time Limit: 1 Sec  Memory Limit: 64 MB Submit: 373  Solved: 247 Description In mil ...

  3. hdu-----(1113)Word Amalgamation(字符串排序)

    Word Amalgamation Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others ...

  4. Word Amalgamation(hdoj1113)

    Word Amalgamation Problem Description In millions of newspapers across the United States there is a ...

  5. hdu1113 Word Amalgamation(详解--map和string的运用)

    版权声明:本文为博主原创文章.未经博主同意不得转载. vasttian https://blog.csdn.net/u012860063/article/details/35338617 转载请注明出 ...

  6. HDOJ.1113 Word Amalgamation(map)

    Word Amalgamation 点我挑战题目 点我一起学习STL-MAP 题意分析 给出字典.之后给出一系列======乱序======单词,要求你查字典,如过这个乱序单词对用有多个有序单词可以输 ...

  7. poj1318 Word Amalgamation 字符串排序(qsort)

    Word Amalgamation Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 9794   Accepted: 4701 ...

  8. poj 1318 Word Amalgamation

    Word Amalgamation Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 9968   Accepted: 4774 ...

  9. hdu 1113 Word Amalgamation 解题报告

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1113 题意:输入一个字典,然后再输入若干单词(每行中,1 <= 单词数 <= 100,并且 ...

随机推荐

  1. PHP网站 通过js方式判断是否是手机访问,若是 跳转到手机版网址!

    <script type="text/javascript" src="http://i3.dukuai.com/ui/js/jquery-1.32pack.js& ...

  2. 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 ...

  3. 357 Count Numbers with Unique Digits 计算各个位数不同的数字个数

    给定一个非负整数 n,计算各位数字都不同的数字 x 的个数,其中 0 ≤ x < 10n.示例:给定 n = 2,返回 91.(答案应该是除[11,22,33,44,55,66,77,88,99 ...

  4. 深入Mysql字符集设置

    作者: Laruence(   ) 本文地址: http://www.laruence.com/2008/01/05/12.html 转载请注明出处 根据Chaos  Wang的PPT整理而成, 在此 ...

  5. Xml的读取

    using System; using System.Collections.Generic; using System.Linq; using System.Web; namespace WebAp ...

  6. input获得焦点和失去焦点

    总结:placeholder因为在IE7 8 9 浏览器不支持所以没用它效果:当input获取光标的时候如果是默认提示则input内容为空.如果不是则为输入内容           当失去光标的时候, ...

  7. 通过yum命令搭建lamp环境(centos6.5)

    centos 6.5 1.yum安装和源代码编译在使用的时候没啥区别,但是安装的过程就大相径庭了,yum只需要3个命令就可以完成,源代码需要13个包,还得加压编译,步骤很麻烦,而且当做有时候会出错,源 ...

  8. JS——模拟百度搜索

    注意事项: 1.for循环移除子节点时,其长度是变化的 2.在文档流中,input.img.p等标签与其他标签有3px的距离,利用左浮动,可以消除3px距离 3.背景图片定位时,第一个值是x轴方向的值 ...

  9. Java_Web三大框架之Hibernate增删改查

    下面介绍一下Hibernate的增删改查. 第一步:编写用户实体类以及User.hbm.xml映射 package com.msl.entity; public class User { privat ...

  10. 13、scala模式匹配

    1.模式匹配的基础语法 2.对类型进行模式匹配 3.对Array和List的元素进行模式匹配 4.case class与模式匹配 5.Option与模式匹配 1.模式匹配的基础语法 Scala提供了m ...