#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; } }
点赞 评论

相关推荐

点赞 评论 收藏
分享
牛油果甜奶昔:别的先不说,牛客还能内推护士?
点赞 评论 收藏
分享
牛客网
牛客网在线编程
牛客网题解
牛客企业服务