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,并且 ...
随机推荐
- JavaScript--Date 日期对象
日期对象可以储存任意一个日期,并且可以精确到毫秒数(1/1000 秒). 定义一个时间对象 : var Udate=new Date(); 注意:使用关键字new,Date()的首字母必须大写. 使 ...
- iOS - UITableView 多选功能实现
:自定义Cell中的代码 #import <UIKit/UIKit.h> @interface TestCell : UITableViewCell @property(nonatomic ...
- 给定的逗号分隔的数字字符串转换为Table
--将给定的逗号分隔的数字字符串转换为Table CREATE FUNCTION [dbo].[fu_Split](@strString nvarchar(4000)) RETURNS @Result ...
- Android开发高手课笔记 - 01 崩溃优化(上):关于“崩溃”那点事
Android 的两种崩溃 Java 崩溃就是在 Java 代码中,出现了未捕获的异常,导致程序异常退出 Native 崩溃一般都是因为在 Native 代码中访问非法地址,也可能是地址对齐出了问题, ...
- C# winform启动外部exe后,如何完全阻断父界面接收事件,扩展waitforexit
公司的系统搭载了好多奇奇怪怪的exe,以前启动exe后,系统还能接着操作.但是后面又提出额外的需求,说是打开外部exe之后,启动exe的父界面要完全不能进行任何操作.当然按常人所想再加一句waitfo ...
- CSS——border
表格细线: <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF ...
- SQL基本操作——函数
函数的类型:在 SQL 中,基本的函数类型和种类有若干种.函数的基本类型是:Aggregate 函数.Scalar 函数. Aggregate 函数:操作面向一系列的值,并返回一个单一的值,下面是SQ ...
- 【转载】HTTP 缓存的四种风味与缓存策略
原文地址:https://segmentfault.com/a/1190000006689795 HTTP Cache 通过网络获取内容既缓慢,成本又高:大的响应需要在客户端和服务器之间进行多次往返通 ...
- cookie和sessionStorage 、localStorage 对比
相同点:都存储在客户端 不同点:1.存储大小 cookie数据大小不能超过4k. sessionStorage和localStorage 虽然也有存储大小的限制,但比cookie大得多,可以达到5M或 ...
- day10-函数基础知识
函数 什么是函数 把工具事先准备好,然后下次使用的时候,直接使用就行了.我们的函数就是工具 为何用函数 1.遇到重复的功能只能重复编写实现代码,代码冗余 2.功能需要扩展时,需要找出所有实现该功能的地 ...