题目
题意:
找到由给定的字符串其中的两个字符串组成的字符串
思路:
利用字符串中的substr查找子字符串,遍历存好的字符串,如果存在一个字符串,
分割成任意两个字串,并且这两个字串在原存储好字符串里面都只出现一次,那么这个字符串就满足要求
易错分析:
一开始存储字符串的时候是EOF结束的
相关题目:
HDU 1247 Hat’s Words
ac代码:
#include<iostream>
#include<set>
#include<string>
using namespace std;
int main()
{
string a,s1,s2;
set<string>s;
int flag=0;
while(cin>>a)
s.insert(a);
for(auto &sub: s)
{
flag=0;
for(int i=1; i<sub.size(); i++)
{
s1=sub.substr(0,i);
s2=sub.substr(i);
if(s.count(s1)&&s.count(s2))
flag=1;
}
if(flag) cout<<sub<<endl;
}
}
/*
_ooOoo_
o8888888o
88" . "88
(| -_- |)
O\ = /O
____/'---'\____
.' \\| |// `.
/ \\||| : |||// \
/ _||||| -:- |||||- \
| | \\\ - /// | |
| \_| ''\---/'' | |
\ .-\__ `-` ___/-. /
___`. .' /--.--\ `. . __
."" '< `.___\_<|>_/___.' >'"".
| | : `- \`.;`\ _ /`;.`/ - ` : | |
\ \ `-. \_ __\ /__ _/ .-` / /
======'-.____`-.___\_____/___.-`____.-'======
`=---='
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
I have a dream! An AC deram!!
*/