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

分析:字符串。对每一个字符串的字母排序生成新的传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的更多相关文章

  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. 看无可看 分治FFT+特征值方程

    题面: 看无可看(see.pas/cpp/c) 题目描述 “What’s left to see when our eyes won’t open?” “若彼此瞑目在即,是否终亦看无可看?” ---- ...

  2. Google广告屏蔽插件adBlock

    今天在博客园写博客的时候发现莫名其妙的在右侧被植入了广告,询问了管理员得知存在以下几种可能: 1.电信网络供应商劫持网页,植入广告 2.ADSafe(是一款去除广告的软件,效果很不错) 但经过最终排除 ...

  3. 网上流行的学生选课相关的50个常用sql语句

    学生表 Student(S#,Sname,Sage,Ssex) 教师表 Teacher(T#,Tname) 课程表 Course(C#,Cname,T#) 学生成绩表 SC(S#,C#,score) ...

  4. Unity学习-鼠标的常用操作(八)

    本次主要介绍5个鼠标事件 void OnMouseEnter():鼠标进入 void OnMouseExit():鼠标移出 void OnMouseDown():鼠标点击 void OnMouseUp ...

  5. iOS图片瘦身总结

    前言 最近在公司写了个小程序来为iOS应用中的图片瘦身,进而减小APP大小,减少用户下载时的流量. 瘦身是在一个专门为图片瘦身的网站进行的. 地址:https://tinypng.com 这个网站提供 ...

  6. Caffe2:ubuntu修改链接方式ln

    参考:文件和目录命令-文件重定向 ln 使用caffe2,产生了此种情况: from caffe2.python import workspace >>WARNING:root:This ...

  7. JavaScript:颜色辨别

    <script> //参考文章:http://www.cnblogs.com/xuechenlei/p/5940729.html //游戏页面:http://www.webhek.com/ ...

  8. 通过javascript在iframe中加载html

    在spring mvc中,虽然有时候,在控制器中设置返回值是json对象,但在拦截器出现错误的时候,仍然可能返回html(根据设置的不同),如果要展示这些html,最好把他们放入iframe中,以防这 ...

  9. 棋盘DP三连——洛谷 P1004 方格取数 &&洛谷 P1006 传纸条 &&Codevs 2853 方格游戏

    P1004 方格取数 题目描述 设有N $\times N$N×N的方格图(N $\le 9$)(N≤9),我们将其中的某些方格中填入正整数,而其他的方格中则放入数字00.如下图所示(见样例): A ...

  10. JS布尔值(Boolean)转换规则

    原文作者: louis 原文链接: http://louiszhai.github.io/2015/12/11/js.boolean/ 语法 众所周知, JavaScript有五个基本的值类型:num ...