首页 > 其他 > 详细

10391 - Compound Words(stl map)

时间:2014-04-02 07:42:19      阅读:389      评论:0      收藏:0      [点我收藏+]

题目:10391 - Compound Words

题目大意:找出有里面出现过的两个单词组成的符合串找出来,按字典序打印。

解题思路:把出现过的单词用map记录下来,然后把每个单词都分两半来考虑是否出现过,两半可以长短不一。

注意:审题要仔细,这题当初就是漏了符合串是由两个单词组成的。

#include<stdio.h>
#include<iostream>
#include<map>
#include<string.h>
#include<string>
using namespace std;

const int N = 120005;
const int M = 100;
map<string, int> s;
char str[N][M];

int main () {
	
	int n = 0, flag;
	while (gets(str[n]) != NULL) {
		
		s[str[n++]] = 1;
	}

	for (int i = 0; i < n; i++) {
		
			for (int j = 1; j < strlen(str[i]); j++) {
			
				char str1[M], str2[M];
				strcpy(str1, str[i]);
				str1[j] = ‘\0‘;
				strcpy(str2, str[i] + j);
	//			printf("%s\n", str2);
				if (s[str1] + s[str2] == 2){
					
					printf("%s\n", str[i]);
					flag = 1; 
					break;
				}	
		} 
	}	
	return 0;
}


10391 - Compound Words(stl map),布布扣,bubuko.com

10391 - Compound Words(stl map)

原文:http://blog.csdn.net/u012997373/article/details/22759443

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!