杭电提交程序时后出现presentation error?该怎么解决
杭电提交程序时后出现presentation error?
RT
我做的是 1002 号题。
A + B Problem II
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 99748 Accepted Submission(s): 18931
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
2
1 2
112233445566778899 998877665544332211
Sample Output
Case 1:
1 + 2 = 3
Case 2:
112233445566778899 + 998877665544332211 = 1111111111111111110
Author
Ignatius.L
我的代码没错误 输入输出也和他要求一样啊,怎么回事?
------解决方案--------------------
RT
我做的是 1002 号题。
A + B Problem II
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 99748 Accepted Submission(s): 18931
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
2
1 2
112233445566778899 998877665544332211
Sample Output
Case 1:
1 + 2 = 3
Case 2:
112233445566778899 + 998877665544332211 = 1111111111111111110
Author
Ignatius.L
我的代码没错误 输入输出也和他要求一样啊,怎么回事?
- C/C++ code
#include <stdio.h> #include <math.h> #include <tchar.h> #include <string.h> #define M 1001 void AddResult(char *, char *); int main(int argc, TCHAR *argv[]) { int LineNum, i, j; char StaFirst[M], StaSecond[M]; char SepFirst[20][M], SepSecond[20][M]; scanf("%d", &LineNum); getchar(); for (i = 0; i < LineNum; i++) { scanf("%s %s", StaFirst, StaSecond); for (j = 0; StaFirst[j] != '\0'; j++) { SepFirst[i][j] = StaFirst[j]; } SepFirst[i][j] = 0; for (j = 0; StaSecond[j] != '\0'; j++) { SepSecond[i][j] = StaSecond[j]; } SepSecond[i][j] = 0; } for (i = 0; i < LineNum; i++) { printf("Case %d:\n%s + %s = ", i + 1, SepFirst[i], SepSecond[i]); AddResult(SepFirst[i], SepSecond[i]); putchar(10); } getchar(); return 0; } void AddResult(char *SepFirst, char *SepSecond) { int Result[M] = { 0 }, Assistant[M] = { 0 }, LenFirst, LenSecond, Lenth; int i, j, CarryFlag = 0; LenFirst = strlen(SepFirst); LenSecond = strlen(SepSecond); if (LenFirst <= LenSecond) { for (i = LenFirst - 1, j = 0; i >= 0; i--, j++) { Assistant[j] = (int)(SepFirst[i] - '0'); } for (i = LenSecond - 1, j = 0; i >= 0; i--, j++) { Result[j] = (Assistant[j] + (int)(SepSecond[i] - '0') + CarryFlag) % 10; CarryFlag = (Assistant[j] + (int)(SepSecond[i] - '0') + CarryFlag) / 10; } if (CarryFlag == 1) { Result[j] = CarryFlag; Lenth = j; } else Lenth = j - 1; } else { for (i = LenSecond - 1, j = 0; i >= 0; i--, j++) { Assistant[j] = (int)(SepSecond[i] - '0'); } for (i = LenFirst - 1, j = 0; i >= 0; i--, j++) { Result[j] = (Assistant[j] + (int)(SepFirst[i] - '0') + CarryFlag) % 10; CarryFlag = (Assistant[j] + (int)(SepFirst[i] - '0') + CarryFlag) / 10; } if (CarryFlag == 1) { Result[j] = CarryFlag; Lenth = j; } else Lenth = j - 1; } for (i = Lenth; i >= 0; i--) { printf("%d", Result[i]); } }
------解决方案--------------------