Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int main() {
- string number;
- cin >> number;
- int sum_of_digits = 0;
- for(int i = 0; i < number.size(); i++) {
- sum_of_digits += (number[i] - '0');
- }
- string result = "";
- for(int i = 0; i < number.size(); i++) {
- int digit = (number[i] - '0');
- for(int j = 0; j <= 9; j++) {
- if(i == 0 and j == 0) {
- continue;
- }
- if(j == digit) {
- continue;
- }
- int tmp_sum = sum_of_digits - digit + j;
- if(tmp_sum % 3 == 0) {
- string tmp_number = number;
- tmp_number[i] = (j + '0');
- if(tmp_number > result) {
- result = tmp_number;
- }
- }
- }
- }
- cout << result << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement