#include <iostream>
using namespace std;
int main() {
string a,b;
int m,k=0;
cout<<"a = "; cin>>a;
cout<<"b = "; cin>>b;
int ind=b.length();
if (a.length()==b.length())
while ((a[k]==b[k]) && (k<b.length()-1)) k++;
for (int i=k; i<b.length()-1; i++) {
if (b[i]==48) break;
m=b[i+1]-48;
if (i<b.length()-2) m--;
if ((b[i]-48)*m < max((b[i]-49),1)*9) {
if ((b[i]-49==0) && (i>0)) continue;
ind=i+1; b[i]--; break;
}
for (int i=ind; i<b.length(); i++) b[i]='9';
if (b[0]=='0') b.erase(0,1);
cout<<b<<endl;
system("pause");
return 0;
var
i, si, N, ss: Integer;
s: string;
begin
Write ('Введите N: ');
ReadLn (N);
s := IntToStr (N);
ss := 0;
for i := 1 to Length (s) do begin
si := StrToInt (s [i]);
if si mod 4 <> 0 then
ss := ss + si;
end;
Writeln ('Сумма цифр = ' + IntToStr (ss));
end.
// второй вариант решения
si, N, ss: Integer;
while N > 0 do begin
si := N mod 10;
N := N div 10;
#include <iostream>
using namespace std;
int main() {
string a,b;
int m,k=0;
cout<<"a = "; cin>>a;
cout<<"b = "; cin>>b;
int ind=b.length();
if (a.length()==b.length())
while ((a[k]==b[k]) && (k<b.length()-1)) k++;
for (int i=k; i<b.length()-1; i++) {
if (b[i]==48) break;
m=b[i+1]-48;
if (i<b.length()-2) m--;
if ((b[i]-48)*m < max((b[i]-49),1)*9) {
if ((b[i]-49==0) && (i>0)) continue;
ind=i+1; b[i]--; break;
}
}
for (int i=ind; i<b.length(); i++) b[i]='9';
if (b[0]=='0') b.erase(0,1);
cout<<b<<endl;
system("pause");
return 0;
}
var
i, si, N, ss: Integer;
s: string;
begin
Write ('Введите N: ');
ReadLn (N);
s := IntToStr (N);
ss := 0;
for i := 1 to Length (s) do begin
si := StrToInt (s [i]);
if si mod 4 <> 0 then
ss := ss + si;
end;
Writeln ('Сумма цифр = ' + IntToStr (ss));
end.
// второй вариант решения
var
si, N, ss: Integer;
begin
Write ('Введите N: ');
ReadLn (N);
ss := 0;
while N > 0 do begin
si := N mod 10;
N := N div 10;
if si mod 4 <> 0 then
ss := ss + si;
end;
Writeln ('Сумма цифр = ' + IntToStr (ss));
end.