Josif_tepe

Untitled

Jun 15th, 2026
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.69 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main() {
  5.     string s;
  6.     cin >> s;
  7.    
  8.     int zbir = 0;
  9.     for(int i = 0; i < s.size(); i++) {
  10.         zbir += s[i] - 48;
  11.     }
  12.    
  13.     string res = "";
  14.    
  15.     for(int i = 0; i < s.size(); i++) {
  16.         int cifra = s[i] - 48;
  17.        
  18.         for(int j = 0; j <= 9; j++) {
  19.             if(cifra != j) {
  20.                 int tmp_zbir = zbir - cifra + j;
  21.                
  22.                 if(tmp_zbir % 3 == 0) {
  23.                     string s2 = s;
  24.                     s2[i] = j + 48;
  25.                     res = max(res, s2);
  26.                 }
  27.             }
  28.         }
  29.     }
  30.    
  31.     cout << res << endl;
  32.    
  33.     return 0;
  34. }
  35.  
Advertisement
Add Comment
Please, Sign In to add comment