其他分享
首页 > 其他分享> > L1-020 帅到没朋友 (20 point(s))

L1-020 帅到没朋友 (20 point(s))

作者:互联网

// 参考后的精简代码
#include <bits/stdc++.h>
using namespace std;

int main(){
	int N, K, M, first = 0;
	string id;
	map<string, int> Moments;
	
	cin >> N;
	while(N--){
		cin >> K;
		for(int i = 0; i < K; i++){
			cin >> id;
			if(K > 1)
				Moments[id]++;
		}
	}

	cin >> M;
	while(M--){
		cin >> id;
		if(Moments[id]++ == 0)
			cout << (first++ ? " " : "") << id;
	}
	if(first == 0) cout << "No one is handsome";
} 
// unordered_set 20 points
#include <bits/stdc++.h>
using namespace std;

int main(){
	int N, K, M, first = 0;
	vector<unordered_set<string>> Moments;
	 
	// 读取朋友圈 
	cin >> N;
	for(int i = 0; i < N; i++){
		unordered_set<string> tmp;
		string str;
		cin >> K;
		
		while(K--){
			cin >> str;
			tmp.insert(str);
		}
		Moments.push_back(tmp);
	}
	
	// 输出标记 
	set<string> isPrint;
	// 查询 
	cin >> M;
	while(M--){
		bool out = true;
		string str; 
		cin >> str;
		
		// 从每个朋友圈中寻找 
		for(int i = 0; i < N; i++){
			
			// 找到朋友则结束寻找  不输出 
			if(Moments[i].size() > 1 && Moments[i].find(str) != end(Moments[i])){
				out = false;
				break;			
			}
		}
		
		// 遍历完都找不到说明是帅哥 && 该人没有输出过 
		if(out == true && isPrint.find(str) == end(isPrint)){
			cout << (first++ ? " " : "") << str;
			isPrint.insert(str); 
		} 
	}
	
	if(isPrint.size() == 0) cout << "No one is handsome";
} 
// vector 17points 错误示范
#include <bits/stdc++.h>
using namespace std;

int main(){
	int N, K, M, first = 0;
	vector<vector<string>> Moments;
	 
	// 读取朋友圈 
	cin >> N;
	for(int i = 0; i < N; i++){
		vector<string> tmp;
		string id;
		cin >> K;
		
		while(K--){
			cin >> id;
			tmp.push_back(id);
		}
		Moments.push_back(tmp);
	}
	
	// 输出标记 
	vector<string> isPrint;
	// 查询 
	cin >> M;
	while(M--){
		bool out = true;
		string id; 
		cin >> id;
		
		// 从每个朋友圈中寻找 
		for(int i = 0; i < N; i++){
			
			// 找到朋友则结束寻找  不输出 
			if(Moments[i].size() > 1 && 
			find(begin(Moments[i]), end(Moments[i]), id) != end(Moments[i])){
				out = false;
				break;			
			}
		}
		
		// 遍历完都找不到说明是帅哥 && 该人没有输出过 
		if(out == true && 
		find(begin(isPrint), end(isPrint), id) == end(isPrint)){
			cout << (first++ ? " " : "") << id;
			isPrint.push_back(id); 
		} 
	}
	
	if(isPrint.size() == 0) cout << "No one is handsome";
} 

标签:20,point,Moments,cin,++,vector,020,id,朋友圈
来源: https://www.cnblogs.com/Atl212/p/15368226.html