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