其实可以优化读入函数的,但考虑到现在的数据多么坑是吧,就酱吧……万一不给你最后那个字符不就T了……
1 #include<iostream> 2 #include<cstdio> 3 #include<cstdlib> 4 #include<cstring> 5 #include<string> 6 #include<algorithm> 7 using namespace std; 8 const int MAXN=10010; 9 struct bign{ 10 int len,s[MAXN]; 11 bign(){memset(s,0,sizeof(s));len=1;} 12 bign(int num){*this=num;} 13 bign(const char *num){*this=num;} 14 bign operator = (const int num){ 15 char s[MAXN]; sprintf(s,"%d",num); 16 *this = s;return *this; 17 } 18 bign operator = (const char *num){ 19 for(int i=0;num[i]=='0';num++); 20 len=strlen(num); 21 for(int i=0;i<len;i++) s[i]=num[len-i-1]-'0'; 22 return *this; 23 } 24 bign operator + (const bign &b) const{ 25 bign c;c.len=0; 26 for(int i=0,g=0;g||i<max(len,b.len);i++) { 27 int x=g; 28 if(i<len) x+=s[i]; 29 if(i<b.len) x+=b.s[i]; 30 c.s[c.len++]=x%10; 31 g=x/10; 32 } return c; 33 } 34 void clean(){while(len > 1 && !s[len-1]) len--;return;} 35 bign operator * (const bign &b){ 36 bign c; 37 c.len=len+b.len; 38 for(int i=0;i<len;i++) for(int j=0;j<b.len;j++) c.s[i+j]+=s[i]*b.s[j]; 39 for(int i=0;i<c.len;i++){ 40 c.s[i+1]+=c.s[i]/10; 41 c.s[i]%=10; 42 } c.clean();return c; 43 } 44 bign operator - (const bign &b){ 45 bign c;c.len=0; 46 for(int i=0,g=0;i<len;i++){ 47 int x=s[i]-g;if(i<b.len) x-=b.s[i]; 48 if(x>=0) g=0; 49 else g=1,x+=10; 50 c.s[c.len++]=x; 51 } c.clean();return c; 52 } 53 bign operator / (const bign &b) { 54 bign c,f=0; 55 for(int i=len-1;i>=0;i--){ 56 f=f*10;f.s[0]=s[i]; 57 while(!(f<b)) f=f-b,c.s[i]++; 58 } c.len=len;c.clean();return c; 59 } 60 bign operator % (const bign &b) { 61 bign r = *this / b; 62 r = *this - r*b; 63 return r; 64 } 65 bool operator < (const bign &b) { 66 if(len!=b.len) return len<b.len; 67 for(int i=len-1;i>=0;i--){ 68 if(s[i]!=b.s[i]) return s[i]<b.s[i]; 69 } return false; 70 } 71 bool operator > (const bign &b){ 72 if(len!=b.len) return len>b.len; 73 for(int i=len-1;i>=0;i--){ 74 if(s[i]!=b.s[i]) return s[i]>b.s[i]; 75 } return false; 76 } 77 bool operator == (const bign &b){ 78 return !(*this>b)&&!(*this<b); 79 } 80 void print(){ 81 for(int i=len-1;i>=0;i--) putchar(s[i]+'0');return; 82 } 83 }; 84 char s[MAXN]; 85 int main(){ 86 bign a,b,c; 87 scanf("%s",s);a=s; 88 scanf("%s",s);b=s; 89 c=a/b;c.print();putchar(' '); 90 c=a%b;c.print(); 91 return 0; 92 }