我是靠谱客的博主 独特未来,这篇文章主要介绍UVA-10391 复合词 题解答案代码 算法竞赛入门经典第二版,现在分享给大家,希望可以做个参考。

GitHub - jzplp/aoapc-UVA-Answer: 算法竞赛入门经典 例题和习题答案 刘汝佳 第二版

AC代码

#include<set>
#include<iostream>
#include<string>
using namespace std;

int main() {
	set<string> se;
	string s;
	int size, i;
	bool flag;
	while(cin >> s) {
		se.insert(s);
	}
	for(auto ip = se.begin(); ip != se.end(); ++ip) {
		size = ip->length() - 1;
		// cout << size << " " << *ip << endl;
		flag = false;
		for(i = 1; i < size; ++i) {
			string s1 = ip->substr(0, i);
			string s2 = ip->substr(i);
			if(se.count(s1) && se.count(s2)) {
				flag = true;
				break;
			}
		}
		if(flag == true) {
			cout << *ip << endl;
		}
	}
	return 0;
}

最后

以上就是独特未来最近收集整理的关于UVA-10391 复合词 题解答案代码 算法竞赛入门经典第二版的全部内容,更多相关UVA-10391内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(48)

评论列表共有 0 条评论

立即
投稿
返回
顶部