-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
94 lines (81 loc) · 1.15 KB
/
main.cpp
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#include<iostream>
using namespace std;
int subtask1(int a, int b)
{
int res;
__asm {
mov eax, a
mov ebx, b
cmp eax, ebx
je a_equal_b
jg a_greater_b
mov eax, b
mov ebx, a
add ebx, 1
cdq
idiv ebx
mov res, eax
jmp the_end
a_equal_b:
mov res, 4
jmp the_end
a_greater_b:
mov eax, a
imul a
imul a
sub eax, 5
cdq
idiv b
mov res, eax
the_end:
}
return res;
}
int subtask2(int n)
{
int res;
__asm {
mov eax, n
mov ebx, 10
xor ecx, ecx
cycle:
inc ecx
cdq
idiv ebx
cmp eax, 0
jne cycle
mov res, ecx
}
return res;
}
int subtask3(int n)
{
int res;
__asm {
mov eax, n
xor ebx, ebx
cycle:
shr eax, 1
jnc cycle
inc ecx
cmp eax, 0
jne cycle
and ecx, 1
mov res, ecx
}
return res;
}
int main()
{
int a,b;
cin >> a >> b;
cout << "Result: " << subtask1(a, b) << endl;
int n;
cin >> n;
cout << "Number of digits: " << subtask2(n) << endl;
int n2;
cin >> n2;
cout << (subtask3(n2)?"ODD number of ones":"EVEN number of ones") << endl;
cout << endl;
return 0;
}