-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.cpp
85 lines (75 loc) · 1.87 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
#include <iostream>
#include <fstream>
#include <sstream>
#include "Bignum.h"
using namespace std;
void test();
void getInput(const string &path_input, const string &path_output);
Bignum calculate(Bignum bignum1, string op, Bignum bignum2);
int main(int argc, char** argv) {
getInput(argv[1], argv[2]);
// test();
return 0;
}
void test(){
int i, j;
for (i = 1; i <= 4 ; ++i) {
for (j = 1; j < 40 - i; ++j) {
printf(" ");
}
for (j = 1; j <= i; ++j) {
printf("%d", j);
}
for (j = i - 1; j > 0; --j) {
printf("%d", j);
}
printf("\n");
}
for (i = 3; i >= 1; --i) {
for (j = 1; j < 40 - i; ++j) {
printf(" ");
}
for (j = 1; j <= i; ++j) {
printf("%d", j);
}
for (j = i - 1; j > 0; --j) {
printf("%d", j);
}
printf("\n");
}
}
void getInput(const string &path_input, const string &path_output){
ifstream in(path_input);
ofstream out(path_output);
if (!in){
cout << "fail to open file " + path_input << endl;
return;
}
if (!out){
cout << "fail to open file " + path_output << endl;
return;
}
string feature;
Bignum bignum1, bignum2;
string op;
getline(in, feature);
while (getline(in, feature)){
stringstream stringin(feature);
stringin >> bignum1;
while (stringin >> op >> bignum2){
bignum1 = calculate(bignum1, op, bignum2);
}
out << bignum1 << endl;
}
}
Bignum calculate(Bignum bignum1, string op, Bignum bignum2){
if (op == "+"){
return bignum1 + bignum2;
} else if(op == "-"){
return bignum1 - bignum2;
} else if(op == "*"){
return bignum1 * bignum2;
} else if (op == "/"){
return bignum1 / bignum2;
}
}