-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path0020.cpp
More file actions
44 lines (41 loc) · 875 Bytes
/
0020.cpp
File metadata and controls
44 lines (41 loc) · 875 Bytes
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
#include <iostream>
#include <vector>
#include <functional>
#include "bigint.h"
void fn1() {
bigint n("1");
for (int i = 1; i <= 100; i++) {
n = n * i;
//n.print();
}
int sum = 0;
for (char c: n.to_string()) {
//std::cout << c;
sum += (c - 48);
}
std::cout << "(WRONG) " << sum << std::endl;
}
void fn2() {
std::vector<short int> num = { 1 };
for (int i = 1; i <= 100; i++) {
int c = 0;
for (int j = 0; j < num.size(); j++) {
num[j] = (num[j] * i) + c;
c = num[j] / 10;
num[j] %= 10;
//std::cout << num[j] << " ";
}
while (c > 0) {
num.push_back(c % 10);
//std::cout << c % 10 << " ";
c /= 10;
}
//std::cout << std::endl;
}
int sum = 0;
for (int i: num) {
sum += i;
}
std::cout << sum << std::endl;
}
std::vector<std::function<void()>> progs = { fn1, fn2 };