1038. Recover the Smallest Number (30) 进行排序,注意comp的写法;
#include <iostream>#include <vector>#include <string>#include <algorithm>using namespace std;bool comp(const string &a,const string &b){ return a+b<b+a;}int main(){ vector<string> v; int n; cin>>n; for(int i=0;i!=n;++i) { string temp; cin>>temp; v.push_back(temp); } sort(v.begin(),v.end(),comp); string ans; for(auto it=v.begin();it!=v.end();++it) ans+=*it; auto it=ans.begin(); while(it!=ans.end()&&(*it)=='0')++it; if(it==ans.end())cout<<0; else while(it!=ans.end()) { cout<<*it;++it; } return 0;}新闻热点
疑难解答