Problem Description
I have a very simple problem for you. Given two integers A and B, your job is to calculate the Sum of A + B.
Input
The first line of the input contains an integer T(1<=T<=20) which means the number of test cases. Then T lines follow, each line consists of two positive integers, A and B. Notice that the integers are very large, that means you should not process them by using 32-bit integer. You may assume the length of each integer will not exceed 1000.
Output
For each test case, you should output two lines. The first line is "Case #:", # means the number of the test case. The second line is the an equation "A + B = Sum", Sum means the result of A + B. Note there are some spaces int the equation. Output a blank line between two test cases.
Sample Input
复制代码
1
2
3
4
5
6
72 1 2 112233445566778899 998877665544332211
Sample Output
复制代码
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
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271Case 1: 1 + 2 = 3 Case 2: 112233445566778899 + 998877665544332211 = 1111111111111111110我勒个去,差点被虐死,这么简单的题,开始我写的一个内联函数max和algorithm里面的函数写得不一样交3次才AC,WA的我给你们几个数据:0001 10000 0000 00009999 11 999999900 0099900999 99900这几个数据和样例全过的话,应该可以AC了LANGUAGE:C++CODE:复制代码#include<stdio.h> #include<string.h> #include<algorithm> #include<stdlib.h> #define maxn 1005 using namespace std; char ans[maxn]; int anslen; void plus(char s1[],char s2[]) { int len1=strlen(s1); int len2=strlen(s2); for(int i=0;i<len1;i++) s1[i]-='0'; for(int i=0;i<len2;i++) s2[i]-='0'; int mid1=len1>>1; int mid2=len2>>1; //printf("%d %d %d %dn",len1,len2,mid1,mid2); for(int i=0;i<mid1;i++) swap(s1[i],s1[len1-1-i]); for(int i=0;i<mid2;i++) swap(s2[i],s2[len2-1-i]); anslen=max(len1,len2); //printf("n anslen= %dn",anslen); int s=0,sum; for(int i=0;i<=anslen;i++) { sum=(s1[i]+s2[i]+s); ans[i]=sum%10; s=sum/10; } } void printans(char ans[],int anslen) { //if(ans[anslen+1]==0) while(anslen>0&&(ans[anslen]==0))anslen--; //else printf("%d",ans[anslen+1]); if(anslen==0) { printf("%dn",ans[0]); return; } for(int i=anslen;i>-1;i--) { printf("%d",ans[i]); } printf("n"); } int main() { int cas; char s1[maxn],s2[maxn]; scanf("%d",&cas); for(int i=1;i<=cas;i++) { memset(s1,0,sizeof(s1)); memset(s2,0,sizeof(s2)); scanf("%s%s",s1,s2); printf("Case %d:n",i); printf("%s + %s = ",s1,s2); plus(s1,s2); printans(ans,anslen); if(i!=cas)printf("n"); } return 0; }
最后
以上就是寒冷发箍最近收集整理的关于HDU 1002 A + B Problem II的全部内容,更多相关HDU内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复