#include <bits/stdc++.h> using namespace std; int main() { int x; vector<int> nums; while(cin >> x){ nums.push_back(x); } auto cmp = [](const int& a, const int& b){ return to_string(a) + to_string(b) < to_string(b) + to_string(a); }; sort(nums.begin(), nums.end(), cmp); string s; for(auto a : nums) s += to_string(a); int index = 0; while(index < s.size() && s[index] == '0') index++; if(index == s.size()) cout << 0 << endl; else cout << s.substr(index) << endl; return 0; } 第二题直接调正则库解决了= = #include <bits/stdc++.h> using namespace std; int main() { string s; while(cin >> s){ regex pattern("[-]?\\d+"); auto numBeg = sregex_iterator(s.begin(), s.end(), pattern); auto numEnd = sregex_iterator(); int res = 0; for(auto i = numBeg; i != numEnd; ++i){ smatch match = *i; string t = match.str(); res += stoi(t); } cout << res << endl; } }
点赞 评论

相关推荐

想顺利毕业的猕猴桃在看牛客:好几个月没面试了,腾讯留面评吗
点赞 评论 收藏
分享
牛客网
牛客企业服务