SHARE
TWEET

Untitled

a guest Oct 23rd, 2019 75 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2. #include <fstream>
  3. #include <string>
  4.  
  5. using namespace std;
  6.  
  7. ifstream fin("reassembly.in");
  8. ofstream fout("reassembly.out");
  9.  
  10. struct bigdata{
  11.     int digi[114];
  12.     bigdata(){
  13.         for(int i = 0; i < 100; i++){
  14.             digi[i] = 0;
  15.         }
  16.     }
  17.     bigdata(string s) : bigdata(){
  18.         for(int i = 0; i < s.size(); i++){
  19.             digi[s.size()-i-1] = s[i]-'0';
  20.         }
  21.     }
  22.     void add(bigdata & rhs){
  23.         int r;
  24.         for(int i = 0; i < 100; i++){
  25.             digi[i] += rhs.digi[i];
  26.             digi[i] += r;
  27.             r = digi[i] / 10;
  28.             digi[i] %= 10;
  29.         }
  30.     }
  31.     void write(ostream & out){
  32.         bool showit = false;
  33.         for(int i = 99; i >= 0; i--){
  34.             if(digi[i] != 0){
  35.                 showit = true;
  36.             }
  37.             if(showit){
  38.                 out << digi[i];
  39.             }
  40.         }
  41.         out << "\n";
  42.     }
  43. };
  44.  
  45. void solveit(){
  46.     bigdata sum;
  47.     string s;
  48.     int n;
  49.     fin >> s >> n;
  50.     while(s.size() % n != 0){
  51.         s += '0';
  52.     }
  53.  
  54.     for(int i = 0; i < s.size()/n; i++){
  55.         bigdata a(s.substr(i*n, n));
  56.         sum.add(a);
  57.     }
  58.     sum.write(fout);
  59. }
  60.  
  61. int main()
  62. {
  63.     for(int acsl = 0; acsl < 5; acsl++){
  64.         solveit();
  65.     }
  66.     return 0;
  67. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top