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 ...
随机推荐
- minicom的安装及配置
1. sudo apt-get install minicom 2. 配置 (1). sudo minicom –s (2). (3). 按“A”配置设备,再按回车保存.按”F”,把留空改为NO.回车 ...
- MATLAB 绘透视图
MATLAB绘图随记(1)--如何画一个透明平面 http://blog.sina.com.cn/s/blog_5cd4cccf0100q90p.html 小老板让我绘个图 找了些资料 最后发现mat ...
- 顶级域名和二级域名共享cookie及相互删除cookie
在CSDN看到一个cookie设置domain时,如何删除的问题, 自己也只知道domain设置为顶级域名时可以被其他二级域名共享,但是如何删除还是有一点搞不清楚,所以特意测试了下cookie和dom ...
- ML平台_饿了么实践
(转载至:https://zhuanlan.zhihu.com/p/28592540) 说到机器学习.大数据,大家听到的是 Hadoop 和 Spark 居多,它们跟 TensorFlow 是一个什么 ...
- 如何让classmethod只允许使用用类对象来调用
Django REST framework里面有这样一段代码,在网上查@classonlymethod的意思是使得classmethod只允许使用用类对象来调用 @classonlymethod de ...
- [VC6,VC9] [ts,nts,deb] [rpm,msi] 你需要下载什么格式的文件
1.VC6与VC9的区别 VC6版本是使用Visual Studio 6编译器编译的,如果你的PHP是用Apache来架设的,那你就选择VC6版本. VC9版本是使用Visual Studio 200 ...
- rsync同步目录
-a, --archive archive mode; equals -rlptgoD (no -H,-A,-X) -r, --recursive recurse into directories - ...
- 【nosql】之ehcache.xml文件属性描述
<ehcache updateCheck="false" name="shiroCache"> <defaultCache <!--最大 ...
- C++中函数的形参为数组时,实质形参是指针
C++中函数的形参如果为数组的话,那么进行实参传递时,实参实际上换转化成指针.参考下面的例子: #include<iostream> using namespace std; void f ...
- 玄学曲线并不玄 教你如何看懂GPU呈现
红色代表了“执行时间”,它指的是Android渲染引擎执行盒子中这些绘制命令的时间,假如当前界面的视图越多,那么红色便会“跳”得越高.实际使用中,比如我们平时刷淘宝App时遇到出现多张缩略图需要加载时 ...