7-2 Anniversary (25 分)

一道简单的字符串题
注意特殊情况

#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
using namespace std;
const int N = 105;
typedef pair<int, string> PII;
int main() {
	//先统计出场的人 然后去哈希表中查出现的人
	unordered_map<string, bool> mp;
	string oldalumni="99999999", oldguest="99999999";
	string olda, oldg;
	int num = 0; 
	int n;
	cin>>n;
	string str, tmp, t;
	for(int i = 0; i < n; i++){
		cin>>str;
		mp[str]= true; 
	}
	int m;
	cin>>m;
	for(int i = 0; i < m; i++){
		cin>>str;
		t = str.substr(6, 8);
		if(mp[str]){
			if(t < oldalumni){
				oldalumni = t;
				olda = str;
			}
			num++;
		}
		if(t < oldguest){
				oldguest = t;
				oldg = str;
		}
	}
	cout<<num<<endl;
	if(num == 0) cout<<oldg<<endl;
	else cout<<olda<<endl;
	return 0;
}

你可能感兴趣的:(PAT甲级真题题解,字符串)