regex

C++11 regex

这是codeforces 75B的代码

#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <map>
#include <set>
#include <regex>
using namespace std;
map<string,int> score;
set<string> nameList;
string me,temp,name[1000];
typedef tuple<int,string> pr;
pr careList[1000];
int n,cnt=1;
void check_and_add(string temp){
	if (nameList.find(temp)==nameList.end()){
		nameList.insert(temp);
		name[cnt++]=temp;
	}
}
int main (int argc, char const* argv[])
{
	regex pattern("(\\w+) (\\w+ ?\\w+) (\\w+)'s ((wall)|(post))"); 
	cmatch result;
	cin>>me>>n;
	getline(cin,temp);
	for (int i=1;i<=n;i++){
		getline(cin,temp);
		if (regex_match(temp.c_str(),result,pattern)){
			check_and_add(result[1]);
			check_and_add(result[3]);
			if (result[3]==me){
				if (result[2]=="posted on")	score[result[1]]+=15;
				if (result[2]=="commented on")	score[result[1]]+=10;
				if (result[2]=="likes")		score[result[1]]+=5;
			}
			if (result[1]==me){
				if (result[2]=="posted on")	score[result[3]]+=15;
				if (result[2]=="commented on")	score[result[3]]+=10;
				if (result[2]=="likes")		score[result[3]]+=5;
				
			}
		}
	}
	for (int i=1;i<cnt;i++)	careList[i]=pr(-score[name[i]],name[i]);
	sort(careList+1,careList+cnt);
	for (int i=1;i<cnt;i++)
		if (get<1>(careList[i])!=me)	cout<< get<1>(careList[i]) <<endl;
	return 0;
}

只是稍微记录一下。

你可能感兴趣的:(regex)