classSolution { public: intminimumSum(int num){ int ans = INT_MAX; string s = to_string(num); int n = s.size(); for (int i = 0; i < n; i ++ ) for (int j = 0; j < n; j ++ ) { if (i == j) continue; string s1; s1.push_back(s[i]); s1.push_back(s[j]); string s2; for (int k = 0; k < n; k ++ ) { if (k != i and k != j) s2.push_back(s[k]); } ans = min(ans, stoi(s1) + stoi(s2)); reverse(begin(s2), end(s2)); ans = min(ans, stoi(s1) + stoi(s2)); } return ans; } };
classSolution { public: vector<int> pivotArray(vector<int>& nums, int p){ vector<int> a, b, c; for (auto& num : nums) { if (num < p) a.push_back(num); if (num == p) b.push_back(num); if (num > p) c.push_back(num); } for (auto& num : b) a.push_back(num); for (auto& num : c) a.push_back(num); return a; } };
constint M = 10; classSolution { public: intminCostSetTime(int start, int moveCost, int pushCost, int tar){ int ans = INT_MAX; for (int i = 1; i < 10000; i ++ ) { string s = to_string(i); string mill, sec; for (int j = s.size() -1; j >= 0; j -- ) { if (sec.size() < 2) sec.push_back(s[j]); else mill.push_back(s[j]); } reverse(begin(sec), end(sec)); reverse(begin(mill), end(mill)); int time = stoi(sec); if (mill.size()) time += stoi(mill) * 60; if (time != tar) continue; vector<int> cnt(M); for (auto& c : s) cnt[c - '0'] ++ ; int cur = 0, prev = start + '0'; for (int j = 0; j < s.size(); j ++) { cur += pushCost; if (s[j] != prev) cur += moveCost; prev = s[j]; } ans = min(ans, cur); // cout << i << ' ' << cur << endl; } return ans; } };