思路:stl大法好 将字符的末尾0给去掉,然后比较string的大小,同时用map的自动排序将名字按照字典序输出,>>>stl大法好
#include<cstdio> #include<cstring> #include<iostream> #include<algorithm> #include<map> #include<set> #include<vector> using namespace std; const int N=2e5+10; map<string,int>a; map<string,string>b; struct node{string a,b;}d[N]; void solve(string &s1){ int len1=s1.size(); auto it=s1.end();it--; while(it!=s1.begin()&&*it==‘0‘) s1.erase(it),it--; } typedef pair<string,string>P;vector<P>vv; bool cmp(P s1,P s2){return s1.second>s2.second||(s1.second==s2.second&&s1.first<s2.first);} int main(){ std::ios::sync_with_stdio(false);cin.tie(0); int n; while(cin>>n){ string s1,s2; while(!vv.empty()) vv.pop_back(); a.clear(),b.clear(); for(int i=1;i<=n;i++){ cin>>s1>>s2; d[i].a=s1,d[i].b=s2; solve(s2);vv.push_back({s1,s2}),a[s1]=i; } int tot=1; sort(vv.begin(),vv.end(),cmp); for(auto it=vv.begin();it!=vv.end();it++){ string tmp=it->first; cout<<tmp<<" "<<d[a[tmp]].b<<endl; } } return 0; }
原文地址:https://www.cnblogs.com/vainglory/p/8933457.html
时间: 2024-10-13 15:55:06