#include <iostream> #include <algorithm> #include <string> #include <vector> #include <numeric> using namespace std; int getMin(vector v) { int minVal = INT_MAX; for (auto e : v) minVal = min(e, minVal); return minVal; } int calc(vector v1, vector v2) { int sum1 = accumulate(v1.begin(), v1.end(), 0); int sum2 = accumulate(v2.begin(), v2.end(), 0); if (sum1 > sum2) { swap(v1, v2); swap(sum1, sum2); } int diff = sum2 - sum1; int ret = 0; if (diff == 0) return ret; else { while (diff > 0) { int tmp = 9 - getMin(v1); auto it = find(v1.begin(), v1.end(), getMin(v1)); *it = 9; diff -= tmp; ++ret; } } return ret; } int main(int argc, char const *argv[]) { string str; cin >> str; vector v; for (auto s : str) v.emplace_back(s - '0'); vector v1(v.begin(), v.begin() + 3); vector v2(v.begin() + 3, v.end()); int res = calc(v1, v2); cout << res << endl; return 0; }
点赞 1

相关推荐

职场水母:为啥你们整简历都喜欢整一大堆没用的,是期待让hr觉得很多,自己很厉害吗
0offer是寒冬太冷还...
点赞 评论 收藏
分享
Java面试先知:我也是和你一样的情况,hr 说等开奖就行了
点赞 评论 收藏
分享
牛客网
牛客网在线编程
牛客网题解
牛客企业服务