Advertisement
Josif_tepe

Untitled

Mar 16th, 2021
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.25 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <cstring>
  4. #include <algorithm>
  5. #include <fstream>
  6. #include <map>
  7. #include <stack>
  8. using namespace std;
  9.  
  10. int main()
  11. {
  12.     string s;
  13.     cin >> s;
  14.     int l = s.size();
  15.     int zbir = 0;
  16.     for(int i = 0; i < l; i++) {
  17.         zbir += (s[i] - '0');
  18.     }
  19.     string najgolem = "";
  20.     for(int i = 0; i < l; i++) {
  21.         int cifra = (s[i] - '0');
  22.         for(int j = 0; j <= 9; j++) {
  23.             if(i == 0 and j != 0 and cifra != j) {
  24.                 int a1 = zbir - cifra;
  25.                 a1 += j;
  26.                 if(a1 % 3 == 0) {
  27.                     s[i] = (j + '0');
  28.                     if(najgolem < s) {
  29.                         najgolem = s;
  30.                     }
  31.                     s[i] = (cifra + '0');
  32.                 }
  33.             }
  34.             else if(cifra != j) {
  35.                 int a1 = zbir - cifra;
  36.                 a1 += j;
  37.                 if(a1 % 3 == 0) {
  38.                     s[i] = (j + '0');
  39.                     if(najgolem < s) {
  40.                         najgolem = s;
  41.                     }
  42.                     s[i] = (cifra + '0');
  43.                 }
  44.                
  45.             }
  46.         }
  47.     }
  48.     cout << najgolem << endl;
  49.     return 0;
  50. }
  51.  
  52. // 999
  53. // 899
  54.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement