uva-10391-枚举
题意:对于输入的字符串,判断是否存在一个单词a=b+c
俩种方法,枚举每一个单词进行拼接,复杂度是n*n
枚举每一个单词,对单词进行substr,判断substr出来的是不在map里面
#include "pch.h"
#include <string>
#include<iostream>
#include<map>
#include<memory.h>
#include<vector> namespace cc
{
using std::cout;
using std::endl;
using std::cin;
using std::map;
using std::vector;
using std::string; constexpr int N = 120000; string a[N];
map<string, int>strMaps;
void solve()
{
int n = 0;
while (cin >> a[n])
{
strMaps[a[n]] = 1;
n++;
}
for (int i=0;i<n;i++)
{
for (int j = 0;j < a[i].size();j++)
{
string str = a[i].substr(0,j+1);
if (strMaps[str] == 0)
continue;
str = a[i].substr(j+1);
if (strMaps[str] == 0)
continue;
cout << a[i] << endl;
break;
} } } }; int main()
{ #ifndef ONLINE_JUDGE
freopen("d://1.text", "r", stdin);
#endif // !ONLINE_JUDGE
cc::solve(); return 0;
}
uva-10391-枚举的更多相关文章
- UVA 10391 stl
https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...
- UVa 10391 (水题 STL) Compound Words
今天下午略感无聊啊,切点水题打发打发时间,=_=|| 把所有字符串插入到一个set中去,然后对于每个字符串S,枚举所有可能的拆分组合S = A + B,看看A和B是否都在set中,是的话说明S就是一个 ...
- UVa 12169 (枚举+扩展欧几里得) Disgruntled Judge
题意: 给出四个数T, a, b, x1,按公式生成序列 xi = (a*xi-1 + b) % 10001 (2 ≤ i ≤ 2T) 给出T和奇数项xi,输出偶数项xi 分析: 最简单的办法就是直接 ...
- UVa 140 (枚举排列) Bandwidth
题意较复杂,请参见原题=_=|| 没什么好说的,直接枚举每个排列就好了,然后记录最小带宽,以及对应的最佳排列. STL里的next_permutation函数真是好用. 比较蛋疼的就是题目的输入了.. ...
- UVa 1151 (枚举 + MST) Buy or Build
题意: 平面上有n个点,现在要把它们全部连通起来.现在有q个套餐,如果购买了第i个套餐,则这个套餐中的点全部连通起来.也可以自己单独地建一条边,费用为两点欧几里得距离的平方.求使所有点连通的最小费用. ...
- Even Parity UVA - 11464 (枚举)
从来没有觉得枚举有多费脑子的.但是这道题还是很香的. 思路:就是非常简单的枚举啦. 从一般的枚举开始考虑.一般的做法就是在所有的格子中有两种状态1, 0. 而一共有225个格子,所有一共要枚举的情 ...
- UVa 1354 枚举子集 Mobile Computing
只要枚举左右两个子天平砝码的集合,我们就能算出左右两个悬挂点到根悬挂点的距离. 但是题中要求找尽量宽的天平但是不能超过房间的宽度,想不到要怎样记录结果. 参考别人代码,用了一个结构体的vector,保 ...
- UVA 10391 - Compound Words 字符串hash
http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&p ...
- uva 10391 Compound Words <set>
Compound Words You are to find all the two-word compound words in a dictionary. A two-word compound ...
- UVA 10391 Compound Words
Problem E: Compound Words You are to find all the two-word compound words in a dictionary. A two-wor ...
随机推荐
- Tensorflow之基于MNIST手写识别的入门介绍
Tensorflow是当下AI热潮下,最为受欢迎的开源框架.无论是从Github上的fork数量还是star数量,还是从支持的语音,开发资料,社区活跃度等多方面,他当之为superstar. 在前面介 ...
- 2017.11.7 ant design - upload 组件的使用, react 条件渲染以及 axios.all() 的使用
一.主要任务:悉尼小程序管理后台,添加景点页面的开发 二.所遇问题及解决 1. 上传多个不同分类音频信息时,如中文音频和英文音频,要求音频不是放在一个数组中的,每个音频是一个独立的字段,此时: < ...
- Hiero中的Events机制
The hiero.core.events module allows you to register method callbacks to respond to events sent by Hi ...
- WPF Demo15 MVVM
项目结构如下: <Window x:Class="MVVMDemo.MainWindow" xmlns="http://schemas.microsoft.com/ ...
- PrintWriter中的write与println方法居然就是这些区别
为什么循环中分别用write方法和println方法效果一样呢? import java.io.*; public class WriteLog { private BufferedReader bf ...
- 黄聪:JQUERY判断操作CHECKBOX选中、取消选中、反选、第二次无法选中的问题
用JQuery做CheckBox全选和反选的时候,遇到一个问题.当用JQ控制全选,全取消一次以后,再次点击全选,发现代码变了,但是CheckBox没有处于选中状态. $("#id" ...
- 【git之】fetch和 pull的区别
Git中从远程的分支获取最新的版本到本地有这样2个命令:1. git fetch:相当于是从远程获取最新版本到本地,不会自动merge Git fetch origin master git log ...
- JVM 专题
未完待续>>> JVM - 整体结构 摘抄自:<分布式java应用基础与实践>-第三章 JVM - 内存 对上图各部分的概要解释: JVM - GC 详情参考: http ...
- Dubbo(5)优化:接口抽取以及依赖版本统一
优化点: 1.在上面provider和consumer程序中都存在DemoProviderService接口了,两个项目中存在同样的东西,代码多余以及不方便管理: 正式的项目中存在很多的接口的,将统一 ...
- Rstdio 中print中文乱码
在Consol中输入 Sys.setlocale("LC_ALL","Chinese") 即可