-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patht.cpp
More file actions
176 lines (141 loc) · 2.73 KB
/
t.cpp
File metadata and controls
176 lines (141 loc) · 2.73 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
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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
#include "tStr.h"
#include <string>
using namespace std;
tStr::tStr(int32_t ibase, int32_t imov, int32_t iexp)
{
t_ibase = ibase;
t_imov = imov;
t_iexp = iexp;
for (int32_t i = 0; i < tNum; i++)
{
sDest[i] = '0';
sTmp[i] = '0';
sBase[i] = '0';
}
int32_t itmp = t_ibase;
int32_t ibIndex = 0;
while (itmp)
{
sBase[ibIndex] = itmp % 10 + '0';
sDest[ibIndex] = itmp % 10 + '0';
itmp = itmp/10;
ibIndex++;
}
ibase_weishu = ibIndex++;
cout <<"ibase_weishu="<<ibase_weishu << endl;
}
tStr::~tStr()
{
}
void tStr::print()
{
int32_t i_re = tNum - 1;
while (sDest[i_re] == '0')
{
i_re--;
}
printf("sDest:");
for (int32_t j3 = i_re; j3 >= 0; j3--)
{
printf("%c", sDest[j3]);
}
printf("\r\n");
#if 0
//
printf("sTmp\r\n");
for (int32_t i = tNum - 1; i >= 0; i--)
printf("%c", sTmp[i]);
printf("\r\n");
//
printf("sBase\r\n");
for (int32_t i = tNum - 1; i >= 0; i--)
printf("%c", sBase[i]);
printf("\r\n");
#endif
}
void tStr::doMultiStrAndInt2Str()
{
cout << "-----------"<< endl;
for (int32_t i =0; i < t_iexp;i++)
{
{
int32_t mi = tNum-1;
while (mi >=0 )
{
sDest[mi] = sBase[mi];
sBase[mi] = '0';
mi--;
}
}
#if 1
int32_t i_re = tNum - 1;
while (sDest[i_re] == '0')
{
i_re--;
}
i_re = i_re + 1;
cout << "exp->" << i + 1 << ":i_len -> "<<i_re << endl;
print();
for (int32_t index = 0; index < i_re; index++)
{
int32_t itmpMult = t_ibase * (sDest[index] - '0') ;
//cout << "index:" << index << "->" << itmpMult << endl;
//one_multipul result -> char[i] + sBase
/*
56789
1234567897899
*/
{
int32_t itmp = itmpMult;
int32_t ibIndex = 0;
while (itmp)
{
sTmp[ibIndex + index] = itmp % 10 + '0';
itmp = itmp / 10;
ibIndex++;
}
//---
//cout <<"ibIndex=" << ibIndex << endl;
// add 2 str :base + tmp ->base
for (int32_t j = 0; j <= ibIndex + index; j++)
{
int32_t t1 = (sTmp[j] - '0') + (sBase[j] - '0');
sBase[j] = t1 % 10 + '0';
int32_t t2 = t1 / 10;
int32_t j1 = 0;
do
{
t1 = sBase[j + j1 + 1] -'0' + t2;
sBase[j + j1 + 1] = t1 % 10 + '0';
t2 = t1 / 10;
j1++;
} while (t2);
//cout << "j1=" << j1 << endl;
}
//-----
#if 0
{
printf("sTmp: ");
for (int32_t i = i_re + index ; i >= 0; i--)
printf("%c", sTmp[i]);
printf("\r");
printf("sBase: ");
for (int32_t i = i_re + index ; i >= 0; i--)
printf("%c", sBase[i]);
printf("\r\n");
}
#endif
//reset sTmp
{
int32_t i = 0;
while (i < tNum)
{
sTmp[i] = '0';
i++;
}
}
}
}
#endif
}
}