set自定义比较函数
2016-07-31 08:47
274 查看
#include<iostream> #include<map> #include<string> #include<climits> #include<set> #include<queue> #include<cstring> using namespace std; struct node{ string s; int cnt; int time; node(){ } node(string a,int b,int c):s(a),cnt(b),time(c){ } // bool operator < (const node & b) const{ // if(cnt>b.cnt) return true; // if(cnt<b.cnt) return false; // return time<b.time; // } }; struct cmp{ bool operator()(const node &a,const node &b) const { if(a.cnt<b.cnt) return false; if(a.cnt>b.cnt) return true; return a.time<b.time; } }; int main() { int t,n; cin>>t; set<node,cmp> st; while(t--){ cin>>n; string s; string ans; int c; st.clear(); for(int i=0;i<n;i++){ cin>>s>>c; node nd(s,c,i); if(st.empty()) st.insert(nd); else{ int ok=0; for(set<node,cmp>::iterator it=st.begin();it!=st.end();it++){ //cout<<(*it).s<<": sds"<<endl; if((*it).s==s){ st.erase(it); node tmp(s,(*it).cnt+c,i); st.insert(tmp); ok=1; break; } } if(!ok) st.insert(nd); } } // for(set<node>::iterator it=st.begin();it!=st.end();it++){ // cout<<(*it).s<<" "<<(*it).cnt<<" "<<(*it).time<<endl; // } set<node,cmp>::iterator it=st.begin(); cout<<(*it).s<<endl; } }
相关文章推荐
- MongoDB Java
- (转)android:layout_gravity和android:gravity的区别
- 怎样回答离职原因
- 擦边球也得有成功趋势才能入
- 暑期集训训练3练习题B - Toxophily(HDU2298)
- 如何在csdn博客中编辑公式
- CSS3初体验之奇技淫巧
- MongoDB 监控
- ext3与ext4文件系统的区别
- Swift:Foundation框架中的NS前缀的由来
- Swift:Foundation框架中的NS前缀的由来
- Swift:Foundation框架中的NS前缀的由来
- CentOS系统如何安装Nginx+PHP+MySQL
- 粉扑怎么用如何用粉扑上粉底
- Stage5--Python GUI编程TKinter
- BestCoder #85 A,B,C
- Stage5--Python GUI编程TKinter
- Java反射获取泛型
- <hdu - 1272> 小希的迷宫 并查集问题 (注意特殊情况)
- HashMap HashTable ConcurrentHashmap