1113.cpp

来自「杭电 acm部分代码 有兴趣的可以下载 谢谢」· C++ 代码 · 共 55 行

CPP
55
字号
#include <iostream>
#include <string>
#include <vector>
#include <set>
using namespace std;
void main(){
	vector<string> dic;
	while(true){
		string word;
		cin >> word;
		if (word == "XXXXXX")
			break;
		dic.push_back(word);
	}
	while(true){
		string word;
		cin >> word;
		if (word == "XXXXXX")
			break;
		multiset<char> chars;
		string::iterator p;
		for (p = word.begin( ); p != word.end( ); ++p)
			chars.insert(*p);
		set<string> result;
		bool matched = false;
		vector<string>::iterator dicp;
		for (dicp = dic.begin( ); dicp != dic.end( ); ++dicp) {
			if (word.length( ) == dicp->length( )) {
				multiset<char> temp(chars);
				string::iterator strp;
				for (strp = dicp->begin( ); strp != dicp->end( ); ++strp) {
					multiset<char>::iterator charp;
					charp = temp.find(*strp);
					if (charp == temp.end( ))
						break;
					temp.erase(charp);
				}
				if (temp.size( ) == 0) {
					result.insert(*dicp);
					matched = true;
				}
			}
		}
		if (!matched)
			cout << "NOT A VALID WORD" << endl;
		else {
			set<string>::iterator p;
			for (p = result.begin( ); p != result.end( ); ++p)
				cout << *p << endl;
		}
		cout << "******" << endl;
	}
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?