This repository was archived by the owner on Aug 5, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmain.cpp
More file actions
73 lines (67 loc) · 2.44 KB
/
main.cpp
File metadata and controls
73 lines (67 loc) · 2.44 KB
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
#include <iostream>
#include <chrono>
#include "TLongInt.h"
int main() {
std::chrono::high_resolution_clock::time_point start = std::chrono::high_resolution_clock::now();
std::string str1, str2;
char op;
while (std::cin >> str1 && std::cin >> str2) {
TLongInt bigInt1(str1);
TLongInt bigInt2(str2);
std::cin >> op;
switch (op) {
case '+':
std::cout << bigInt1 + bigInt2 << std::endl;
break;
case '>':
std::cout << (bigInt1 > bigInt2 ? "true" : "false") << std::endl;
break;
case '<':
std::cout << (bigInt1 < bigInt2 ? "true" : "false") << std::endl;
break;
case '=':
std::cout << (bigInt1 == bigInt2 ? "true" : "false") << std::endl;
break;
case '-':
if (bigInt1 >= bigInt2) {
std::cout << bigInt1 - bigInt2 << std::endl;
} else {
std::cout << "Error" << std::endl;
}
break;
case '*':
std::cout << bigInt1 * bigInt2 << std::endl;
break;
case '^':
if (bigInt1 == TLongInt(1, 0)) {
if (bigInt2 == TLongInt(1, 0)) {
std::cout << "Error" << std::endl;
} else {
std::cout << 0 << std::endl;
}
} else if (bigInt1 == TLongInt(1, 1)) {
std::cout << 1 << std::endl;
} else {
int numPow = std::stoi(str2);
std::cout << (bigInt1 ^ numPow) << std::endl;
}
break;
case '/':
if (bigInt2 == TLongInt(1, 0)) {
std::cout << "Error" << std::endl;
} else {
std::cout << bigInt1 / bigInt2 << std::endl;
}
break;
default:
std::cout << "Error" << std::endl;
break;
}
}
std::chrono::high_resolution_clock::time_point end = std::chrono::high_resolution_clock::now();
std::cout << "TLongInt: " << std::endl;
std::cout << "Time of working ";
std::cout << std::chrono::duration_cast<std::chrono::milliseconds>( end - start ).count();
std::cout << " ms." << std::endl;
return 0;
}