// Task04.cpp : Defines the entry point for the console application. // #include "stdafx.h" #include #include #include #include #include using namespace std; int _tmain(void) { string str; getline(cin, str); auto len = str.length(); vector num(len); transform(begin(str), end(str), begin(num), [](char ch){ return ch - 48; }); auto sum = 3 - accumulate(begin(num), end(num), 0) % 3; auto replace = false; for (auto i = 2; i >= 0; i--) { auto res = find_if(begin(num), end(num), [sum, i](unsigned short s_i){ return (s_i + sum + i * 3) < 10; }); if (res != end(num)) { *res += (sum + i * 3); replace = true; break; } } if (!replace) num[len-1] -= sum; copy(begin(num), end(num), ostream_iterator(cout)); return 0; }