Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <cstring>
- #include <algorithm>
- #include <fstream>
- #include <map>
- #include <stack>
- using namespace std;
- int main()
- {
- string s;
- cin >> s;
- int l = s.size();
- int zbir = 0;
- for(int i = 0; i < l; i++) {
- zbir += (s[i] - '0');
- }
- string najgolem = "";
- for(int i = 0; i < l; i++) {
- int cifra = (s[i] - '0');
- for(int j = 0; j <= 9; j++) {
- if(i == 0 and j != 0 and cifra != j) {
- int a1 = zbir - cifra;
- a1 += j;
- if(a1 % 3 == 0) {
- s[i] = (j + '0');
- if(najgolem < s) {
- najgolem = s;
- }
- s[i] = (cifra + '0');
- }
- }
- else if(cifra != j) {
- int a1 = zbir - cifra;
- a1 += j;
- if(a1 % 3 == 0) {
- s[i] = (j + '0');
- if(najgolem < s) {
- najgolem = s;
- }
- s[i] = (cifra + '0');
- }
- }
- }
- }
- cout << najgolem << endl;
- return 0;
- }
- // 999
- // 899
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement