提交时间:2023-05-13 18:06:51
运行 ID: 17270
// http://bnucode.com/p/701169 #include<iostream> #include<cstring> using namespace std; struct bign{ int len; int d[1000]; bign(){ len = 0; memset(d, 0, sizeof(d)); } }; bign change(char str[]){ // 将整数(字符串)转换为bign bign c; for(int i = 0; i < strlen(str); i++){ c.d[c.len++] = str[i] - '0'; } return c; } bign sub(bign a, bign b){ // 高精度 a - b bign c; for(int i = 0; i < a.len; i++){ if(a.d[i] >= b.d[i]){ c.d[c.len++] = a.d[i] - b.d[i]; } else{ a.d[i+1] -= 1; c.d[c.len++] = a.d[i] + 10 - b.d[i]; } } return c; } void print(bign a){ for(int i = a.len - 1; i >= 0; i--){ printf("%d", a.d[i]); } } int main() { char s1[205], s2[205]; gets(s1); gets(s2); bign a = change(s1), b = change(s2); bign c = sub(a, b); print(c); return 0; }