zoukankan      html  css  js  c++  java
  • 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;
    }
    

    只是稍微记录一下。

  • 相关阅读:
    旁友数独会伐啦?python秒解数独了解下伐啦?
    趁老王不在,和隔壁邻居斗斗地主,比比大小
    ll字段 详解 文件权限
    etc/pass命令列表
    maven配置
    linux常用汇总
    Tomcat学习笔记
    JavaEE高级-Hibernate学习笔记
    JavaEE高级-通用Mapper学习笔记
    jQueryrocket
  • 原文地址:https://www.cnblogs.com/loveidea/p/4385206.html
Copyright © 2011-2022 走看看