132{
133//将两数对应位相减
134maxNumberArray[j]-=minNumberArray[j];
135if(maxNumberArray[j]<0)//若是相减成果为负,用递归向高位借位
136{
137maxNumberArray[j]+=10;
138ComputeCarry(maxNumberArray,j+1);
139}
140}
141
142if(negative)
143return"-"+ReverseIntArrayAndToString(maxNumberArray);
144returnReverseIntArrayAndToString(maxNumberArray);
145}
146//向高位借位的递归算法
147privatestaticvoidComputeCarry(int[]numberArray,intp)
148{
149if(numberArray[p]>0)//若是高位够借位
150{
151numberArray[p]--;
152}
153else//若是高位不敷借,持续递归借位
154{
155numberArray[p]=9;
156ComputeCarry(numberArray,p+1);
157}
158}
159//将字符情势默示的数按位存入int数组,并反转过来以便于策画
160privatestaticint[]ConvertStringToIntArrayAndReverse(stringstr)
161{
162int[]result=newint[str.Length];
163for(inti=str.Length-1,j=0;i>=0;i--,j++)
164{
165result[j]=Convert.ToInt32(str[i].ToString());
166}
167returnresult;
168}
169//向高位借位的递归算法
170privatestaticvoidComputeCarry(int[]numberArray,intp)
171{
172if(numberArray[p]>0)//若是高位够借位
173{
174numberArray[p]--;
175}
176else//若是高位不敷借,持续递归借位
177{
178numberArray[p]=9;
179ComputeCarry(numberArray,p+1);
180}
181}
182//将字符情势默示的数按位存入int数组,并反转过来以便于策画
183privatestaticint[]ConvertStringToIntArrayAndReverse(stringstr)
184{
185int[]result=newint[str.Length];
186for(inti=str.Length-1,j=0;i>=0;i--,j++)
187{
188result[j]=Convert.ToInt32(str[i].ToString());
189}
190returnresult;
191}
192//向高位借位的递归算法
193privatestaticvoidComputeCarry(int[]numberArray,intp)
194{
195if(numberArray[p]>0)//若是高位够借位
196{
197numberArray[p]--;
198}
199else//若是高位不敷借,持续递归借位
200{
201numberArray[p]=9;
202ComputeCarry(numberArray,p+1);
203}
204}
205//将字符情势默示的数按位存入int数组,并反转过来以便于策画
206privatestaticint[]ConvertStringToIntArrayAndReverse(stringstr)
207{
208int[]result=newint[str.Length];
209for(inti=str.Length-1,j=0;i>=0;i--,j++)
210{
211result[j]=Convert.ToInt32(str[i].ToString());
212}
213returnresult;
214}
215//向高位借位的递归算法
216privatestaticvoidComputeCarry(int[]numberArray,intp)
217{
218if(numberArray[p]>0)//若是高位够借位
219{
220numberArray[p]--;
221}
222else//若是高位不敷借,持续递归借位
223{
224numberArray[p]=9;
225ComputeCarry(numberArray,p+1);
226}
227}
228//将字符情势默示的数按位存入int数组,并反转过来以便于策画
229privatestaticint[]ConvertStringToIntArrayAndReverse(stringstr)
230{
231int[]result=newint[str.Length];
232for(inti=str.Length-1,j=0;i>=0;i--,j++)
233{
234result[j]=Convert.ToInt32(str[i].ToString());
235}
236returnresult;
237}
238//向高位借位的递归算法
239privatestaticvoidComputeCarry(int[]numberArray,intp)
240{
241if(numberArray[p]>0)//若是高位够借位
242{
243numberArray[p]--;
244}
245else//若是高位不敷借,持续递归借位
246{
247numberArray[p]=9;
248ComputeCarry(numberArray,p+1);
249}
250}
251//将字符情势默示的数按位存入int数组,并反转过来以便于策画
252privatestaticint[]ConvertStringToIntArrayAndReverse(stringstr)
253{
254int[]result=newint[str.Length];
255for(inti=str.Length-1,j=0;i>=0;i--,j++)
256{
257result[j]=Convert.ToInt32(str[i].ToString());
258}
259returnresult;
260}
261//向高位借位的递归算法
262privatestaticvoidComputeCarry(int[]numberArray,intp)
263{
264if(numberArray[p]>0)//若是高位够借位
265{
266numberArray[p]--;
267}
268else//若是高位不敷借,持续递归借位
269{
270numberArray[p]=9;
271ComputeCarry(numberArray,p+1);
272}
273}
274//将字符情势默示的数按位存入int数组,并反转过来以便于策画
275privatestaticint[]ConvertStringToIntArrayAndReverse(stringstr)
276{
277int[]result=newint[str.Length];
278for(inti=str.Length-1,j=0;i>=0;i--,j++)
279{
280result[j]=Convert.ToInt32(str[i].ToString());
281}
282returnresult;
283}
1//将终极策画成果反转回来并拼成字符串
2privatestaticstringReverseIntArrayAndToString(int[]intArray)
3{
4IEnumerabletmp=intArray.Reverse();
5StringBuilderstrBld=newStringBuilder();
6foreach(intiintmp)
7strBld.Append(i);
8returnstrBld.ToString().TrimStart(""0"");
9}
10}
本文由成都网站建设:
成都公司代理:
组织发布。