Untitled

mail@pastecode.io avatar
unknown
plain_text
2 years ago
1.4 kB
2
Indexable
Never
#include <iostream>
#include <fstream>
#include <cmath>
#include <algorithm>

using namespace std;
ifstream infile("input.txt");
int n=10000;
bool flag=false;
long long int a[n];
long long int b[n];

void f(string &s){
    int l = s.size()-1;
    int r;
    long long res[n];
    for (int i=0;i<n;i++){
        res[i] = 0;
    }
    char ss[2];
    ss[1] = '\0';
    int ind = 0;
    for (int i=0;i<s.size();i++){
        ss[0]=s[i];
        r = atoi(ss);
        res[l] = r;
        l--;
    }
    if (!flag){
        a=res;
        flag=true;
    } else {
        b = res;
    }
}

int main()
{  
    for (int i=0;i<n;i++){
        a[i] = 0;
        b[i] = 0;
    }
    if (infile.is_open()) {
        string line;
        while (getline(infile, line)) {
            string::iterator it = remove(line.begin(), line.end(), '\r');
            line.erase(it, line.end());
            f(line);
        }
    }
    
    int r=0;
    for (int j=n-1;j>-1;j--){
        r = a[j]+b[j]+r;
        a[j]=r%n;
        r/=n;
    }
    int i=0;
    while (!a[i]){
        i++;
    }
    ofstream outfile("output.txt");
    
    int p;
    outfile<<a[i];
    i++;
    for (i;i<n;i++){
        p=100;
        while (p>0){
            outfile<<a[i]/p;
            a[i]%=p;
            p/=10;
        }
    }
    
}