Это пока только тестовое, можешь проверить, код сырой
n,m = map(int, input().split())
n = str(n)
sum_num_n = sum([int(i) for i in n])
if sum_num_n < m:
def count_num(x):
if x/9 > x//9 :
return x//9 + 1
return x//9
count = count_num(m)
n += '0'*(count-len(n))
n = list(n[::-1])
i = 0
nujno = m - sum_num_n
while nujno!= 0:
if nujno+int(n[i]) < 9:
n[i] = str(int(n[i])+nujno)
break
else:
nujno-=9-int(n[i])
n[i] = '9'
i+=1
print(''.join(n[::-1]))
while True:
if i == len(n)-1 :
n.append('0')
if n[i+1] == 9:
continue
n[i+1] = str(int(n[i+1])+1)
nujno-=1
if int(n[i])+nujno > 0:
nujno+=int(n[i])
n[i] = '0'
if nujno == 0:
С++
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#include "lib.h"
int showMenu(){
int choise;
do{
cout << "1) Authorization." << endl;
cout << "2) Registration." << endl;
cout << "3) Exit." << endl;
cout << "Make your choise: ";
cin >> choise;
if(cin.fail()){
cin.clear();
cin.ignore();
system("cls");
cout << "Input is incorrect.\n";
}
}while(choise <1 || choise >3);
return choise;
void registerUser(){
cout << " Registration \n";
cout << "Type your login (30 symbols max): ";
char login[31] = {0};
cin >> login;
cout << "Type password: ";
char password[32] = {0};
cin >> password;
cout << "Confirmation: ";
char password2[32] = {0};
cin >> password2;
FILE *f = NULL;
fopen_s(&f, "base.txt", "at");
if(f){
fprintf_s(f,"%s;%s\n",login, password);
fclose(f);
} else {
cout << "Registration is fail. File is not created.\n";
bool checkUser(char* aLogin, char* aPassword){
fopen_s(&f, "base.txt", "rt");
while(!feof(f)){
char buff[100] = {0};
fgets(buff,99,f);
if(strlen(buff)){
buff[strlen(buff) - 1] = '\0';
char *login = buff;
char *password = strstr(buff,";") + 1;
*(password - 1) = '\0';
/*cout << "Login:" << login << endl;
cout << "Password:" << password << endl;*/
if(_stricmp(aLogin,login) == 0 &&
_stricmp(aPassword,password) == 0
)
return true;
cout << "Users file does not exists.\n";
return false;
Это пока только тестовое, можешь проверить, код сырой
n,m = map(int, input().split())
n = str(n)
sum_num_n = sum([int(i) for i in n])
if sum_num_n < m:
def count_num(x):
if x/9 > x//9 :
return x//9 + 1
return x//9
count = count_num(m)
n += '0'*(count-len(n))
n = list(n[::-1])
i = 0
nujno = m - sum_num_n
while nujno!= 0:
if nujno+int(n[i]) < 9:
n[i] = str(int(n[i])+nujno)
break
else:
nujno-=9-int(n[i])
n[i] = '9'
i+=1
print(''.join(n[::-1]))
else:
n = list(n[::-1])
i = 0
nujno = m - sum_num_n
while True:
if i == len(n)-1 :
n.append('0')
if n[i+1] == 9:
continue
else:
n[i+1] = str(int(n[i+1])+1)
nujno-=1
if int(n[i])+nujno > 0:
n[i] = str(int(n[i])+nujno)
break
else:
nujno+=int(n[i])
n[i] = '0'
if nujno == 0:
break
i+=1
print(''.join(n[::-1]))
С++
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#include "lib.h"
int showMenu(){
int choise;
do{
cout << "1) Authorization." << endl;
cout << "2) Registration." << endl;
cout << "3) Exit." << endl;
cout << "Make your choise: ";
cin >> choise;
if(cin.fail()){
cin.clear();
cin.ignore();
system("cls");
cout << "Input is incorrect.\n";
}
}while(choise <1 || choise >3);
return choise;
}
void registerUser(){
system("cls");
cout << " Registration \n";
cout << "Type your login (30 symbols max): ";
char login[31] = {0};
cin >> login;
cout << "Type password: ";
char password[32] = {0};
cin >> password;
cout << "Confirmation: ";
char password2[32] = {0};
cin >> password2;
FILE *f = NULL;
fopen_s(&f, "base.txt", "at");
if(f){
fprintf_s(f,"%s;%s\n",login, password);
fclose(f);
} else {
cout << "Registration is fail. File is not created.\n";
}
}
bool checkUser(char* aLogin, char* aPassword){
FILE *f = NULL;
fopen_s(&f, "base.txt", "rt");
if(f){
while(!feof(f)){
char buff[100] = {0};
fgets(buff,99,f);
if(strlen(buff)){
buff[strlen(buff) - 1] = '\0';
char *login = buff;
char *password = strstr(buff,";") + 1;
*(password - 1) = '\0';
/*cout << "Login:" << login << endl;
cout << "Password:" << password << endl;*/
if(_stricmp(aLogin,login) == 0 &&
_stricmp(aPassword,password) == 0
)
return true;
}
}
fclose(f);
} else {
cout << "Users file does not exists.\n";
}
return false;
}