传送门
1 /*
2 * input: an expression seperated by a '-' or '+'; for example: a-b, a+b
3 * ouput: the answer of the input expression
4 */
5 #include <stdio.h>
6 #include <string.h>
7
8 #define MAX_N 205
9
10 char a[MAX_N], b[MAX_N], ans[MAX_N];
11 char op;
12
13 void reverse(char *s) {
14 size_t len = strlen(s);
15 size_t i;
16
17 for (i = 0; i < (len>>1); i++) {
18 s[i] ^= s[len-i-1];
19 s[len-i-1] ^= s[i];
20 s[i] ^= s[len-i-1];
21 }
22 }
23
24 void balance(char *a, char *b) {
25 size_t len_a = strlen(a);
26 size_t len_b = strlen(b);
27
28 while (len_a < len_b) {
29 a[len_a++] = '0';
30 a[len_a] = '