Advertisement
Josif_tepe

Untitled

Feb 25th, 2023
726
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.92 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5.  
  6. int main() {
  7.     string number;
  8.     cin >> number;
  9.    
  10.     int sum_of_digits = 0;
  11.    
  12.     for(int i = 0; i < number.size(); i++) {
  13.         sum_of_digits += (number[i] - '0');
  14.     }
  15.     string result = "";
  16.     for(int i = 0; i < number.size(); i++) {
  17.         int digit = (number[i] - '0');
  18.        
  19.         for(int j = 0; j <= 9; j++) {
  20.             if(i == 0 and j == 0) {
  21.                 continue;
  22.             }
  23.             if(j == digit) {
  24.                 continue;
  25.             }
  26.             int tmp_sum = sum_of_digits - digit + j;
  27.             if(tmp_sum % 3 == 0) {
  28.                 string tmp_number = number;
  29.                 tmp_number[i] = (j + '0');
  30.                
  31.                 if(tmp_number > result) {
  32.                     result = tmp_number;
  33.                 }
  34.             }
  35.            
  36.         }
  37.     }
  38.     cout << result << endl;
  39.     return 0;
  40. }
  41.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement