标签:
1 #include <cstdio> 2 #include <cmath> 3 #include <cstring> 4 #include <ctime> 5 #include <iostream> 6 #include <istream> 7 #include <ostream> 8 #include <algorithm> 9 #include <set> 10 #include <vector> 11 #include <sstream> 12 #include <queue> 13 #include <typeinfo> 14 #include <fstream> 15 #include <map> 16 #include <stack> 17 using namespace std; 18 #define INF 100000 19 typedef long long ll; 20 const int maxn=1010; 21 struct BigInteger { 22 static const int BASE = 100000000; 23 static const int WIDTH = 8; 24 vector<int> s; 25 26 BigInteger(long long num = 0) { *this = num; } 27 BigInteger operator = (long long num) { 28 s.clear(); 29 do { 30 s.push_back(num % BASE); 31 num /= BASE; 32 } while(num > 0); 33 return *this; 34 } 35 BigInteger operator = (const string& str) { 36 s.clear(); 37 int x, len = (str.length() - 1) / WIDTH + 1; 38 for(int i = 0; i < len; i++) { 39 int end = str.length() - i*WIDTH; 40 int start = max(0, end - WIDTH); 41 sscanf(str.substr(start, end-start).c_str(), "%d", &x); 42 s.push_back(x); 43 } 44 return *this; 45 } 46 BigInteger operator + (const BigInteger& b) const { 47 BigInteger c; 48 c.s.clear(); 49 for(int i = 0, g = 0; ; i++) { 50 if(g == 0 && i >= s.size() && i >= b.s.size()) break; 51 int x = g; 52 if(i < s.size()) x += s[i]; 53 if(i < b.s.size()) x += b.s[i]; 54 c.s.push_back(x % BASE); 55 g = x / BASE; 56 } 57 return c; 58 } 59 }; 60 61 ostream& operator << (ostream &out, const BigInteger& x) { 62 out << x.s.back(); 63 for(int i = x.s.size()-2; i >= 0; i--) { 64 char buf[20]; 65 sprintf(buf, "%08d", x.s[i]); 66 for(int j = 0; j < strlen(buf); j++) out << buf[j]; 67 } 68 return out; 69 } 70 71 istream& operator >> (istream &in, BigInteger& x) { 72 string s; 73 if(!(in >> s)) return in; 74 x = s; 75 return in; 76 } 77 set<BigInteger> s; 78 79 int main() 80 { 81 int t,times=0,tmp; 82 BigInteger a,b; 83 scanf("%d",&t); 84 tmp=t; 85 while(t--){ 86 cin>>a>>b; 87 BigInteger sum=a+b; 88 printf("Case %d:\n",++times); 89 cout<<a<<" + "<<b<<" = "<<sum<<endl; 90 if(times!=tmp) printf("\n"); 91 } 92 return 0; 93 }
标签:
原文地址:http://www.cnblogs.com/RRirring/p/4728501.html