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

分析:字符串。对每一个字符串的字母排序生成新的传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. ACM_无聊者序列(斐波那契数列大数取余(同余)+规律)

    Problem Description: 瓜瓜在玩着由红色和蓝色的大理石做成的玻璃珠,他将n个玻璃珠从左到右排成一个序列叫做无聊者序列.一个非空的红色和蓝色玻璃珠组成的序列是一个无聊者序列.这个序列的 ...

  2. day03_12/13/2016_bean属性的设置之setter方法注入

  3. 开始玩qt,使用代码修改设计模式生成的菜单

    之前制作菜单时,不是纯代码便是用设计模式 直接图形化完成. 今天我就是想用代码修改已经存在的菜单项,如果是用代码生成的可以直接调用指针完成: 但通过设计模式完成的没有暴露指针给我,至少我没发现. 在几 ...

  4. Spring.net(v1.3.2) 官网API-第一章 前言

    虽然有很好的工具和技术,但是开发软件应用仍然是很困难的.Spring为构建企业级应用提供了一个轻量级的解决方案,Spring提供了一个统一的.透明的方式去配置你的应用,和将AOP集成到你的软件中.Sp ...

  5. Laravel5.1学习笔记15 数据库1 数据库使用入门

    简介 运行原生SQL查询  监听查询事件 数据库事务 使用多数据库连接 简介 Laravel makes connecting with databases and running queries e ...

  6. 移动web——bootstrap响应式工具

    基本介绍 1.利用媒体查询功能并使用这些工具类可以方便的针对不同设备展示或隐藏页面内容. 基本使用 <!DOCTYPE html> <html lang="zh-CN&qu ...

  7. json 新用

    如果使用struts2的action,可以省去属性赋值的工夫. 但是假如你没有使用struts2,而且使用的是ajax请求,通过json来传递参数.那我下面所说的对你可能是一个很好的解脱,从此告别re ...

  8. 离线安装Selenium

    https://blog.csdn.net/poem_ruru/article/details/79032140

  9. javascript模块化编程(一)(http://www.ruanyifeng.com/blog/2012/10/javascript_module.html)

    Javascript模块化编程(一):模块的写法   随着网站逐渐变成"互联网应用程序",嵌入网页的Javascript代码越来越庞大,越来越复杂. 网页越来越像桌面程序,需要一个 ...

  10. hdu 2084 数塔(简单dp)

    题目 简单dp //简单的dp #include<stdio.h> #include<string.h> #include<algorithm> using nam ...