1066 图像过滤 测试点3超时问题

易错点

这道题用cin会超时,scanf比cin快!

代码

#include <iostream>
#include <cstdio>
#include <set>
#include <string>
using namespace std;
string x[100000];
int main()
{
	int n;
	string a,b;
	int m;
	string c;
	set<string> st;
	set<string> st2;
	int cnt=0;
	for(int i=0;i<100000;i++){
		x[i]="0";
	}
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>a>>b;
		x[stoi(a)]=b;
		x[stoi(b)]=a;
	}
	cin>>m;
	for(int i=0;i<m;i++){
		cin>>c;
		st.insert(c);
	}
	for(set<string>::iterator it=st.begin();it!=st.end();it++){
		if(x[stoi(*it)]=="0"){
			cnt++;
			st2.insert(*it);
		}
		else{
			if(st.find(x[stoi(*it)])!=st.end()){
				;
			}
			else{
				cnt++;
				st2.insert(*it);
			}
		}
	}
	cout<<cnt<<endl;
	int tmp=0;
	for(set<string>::iterator it=st2.begin();it!=st2.end();it++){
		if(tmp==0){
			cout<<*it;
			tmp=1;
		}
		else{
			cout<<" "<<*it;
		}
	}
	return 0;
}
posted @ 2022-07-11 21:44  qwasdasd  阅读(28)  评论(0)    收藏  举报