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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
|
#include <iostream>
#include <cmath>
using namespace std;
/*
* Exercise 1
*/
double f(unsigned int k, int x) {
double sum = x;
for (unsigned int i = 2; i <= k; i++) {
if (i & 1) // if odd
sum = 3 * sum + 1;
else
sum /= 2;
}
return sum;
}
void ex1() {
int x;
cin >> x;
cout << f(35, x) << endl;
}
/*
* Exercise 2
*/
void setMarmaladeType(int type, int *blueberryMarmalades, int *peachMarmalades, int *rosehipMarmalades) {
if (type % 7 == 0) *blueberryMarmalades += 1;
else if (type % 13 == 0) *peachMarmalades += 1;
else if (type % 17 == 0) *rosehipMarmalades += 1;
}
void ex2() {
int archiveLength;
cin >> archiveLength;
int blueberryMarmalades = 0, peachMarmalades = 0, rosehipMarmalades = 0;
for (int i = 0, digit, countryDigits, typeDigits, type; i < archiveLength; i++) {
cin >> digit;
cout << digit;
if (i % 8 == 0) {
countryDigits = 1;
typeDigits = type = 0;
}
else if (countryDigits < 3) {
countryDigits++;
}
else if (typeDigits < 4) {
typeDigits++;
(type *= 10) += digit;
}
else if (typeDigits == 4) {
cout << endl;
setMarmaladeType(type, &blueberryMarmalades, &peachMarmalades, &rosehipMarmalades);
}
}
cout << "Мармалад от боровинки: " << blueberryMarmalades << endl;
cout << "Мармалад от праскови: " << peachMarmalades << endl;
cout << "Шипков мармалад: " << rosehipMarmalades << endl;
}
/*
* Exercise 4
*/
bool isInteresting(int n) {
int lastDigit;
do {
lastDigit = n % 10;
n /= 10;
if ((lastDigit & 1) == ((n % 10) & 1))
return false;
} while (n != 0);
return true;
}
int sumOfInterestingNumsBetween(int a, int b) {
int sum = 0;
for (int i = a; i <= b; i++) {
if (isInteresting(i))
sum += i;
}
return sum;
}
void ex4() {
int a, b;
cin >> a >> b;
cout << sumOfInterestingNumsBetween(a, b) << endl;
}
int main() {
ex4();
}
|