fbpx

Problema #2393 – SumaXXL – Rezolvari PBInfo

de Mihai-Alexandru

Cerința

Numim număr mare un număr care conține prea multe cifre pentru a fi memorat în tipurile existente.

Exemplu

sumaxxl.in

20 7 8 5 3 7 6 7 1 4 6 9 9 4 3 4 6 6 9 9 9
25 7 6 3 9 6 3 1 3 6 5 9 5 8 9 1 6 7 9 5 4 5 3 6 5 3

sumaxxl.out

7639709903630386738920652

Explicație

78537671469943466999 + 7639631365958916795453653 = 7639709903630386738920652

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
#include<fstream>
using namespace std;
ifstream cin("sumaxxl.in");
ofstream cout("sumaxxl.out");
int a[101], b[101];
int main()
{
int n , m , t = 0;
cin >> n;
for(int i = 1 ; i <= n ; ++i)cin >> a[i];
for(int i = 1 ; i <= n / 2 ; ++i)swap(a[i] , a[n-i+1]);
cin >> m;
for(int j = 1 ; j <= m ; ++j)cin >> b[j];
for(int i = 1 ; i <= m / 2 ; ++i)swap(b[i] , b[m-i+1]);
if(m > n) n = m;
for(int i = 1 ; i <= n ; i++)
{
int c = a[i] + b[i] + t;
a[i] = c % 10;
t = c / 10;
}
if(t > 0) a[++n] = t;
for(int i = n ; i >= 1 ; i--) cout << a[i];
return 0;
}
#include<fstream> using namespace std; ifstream cin("sumaxxl.in"); ofstream cout("sumaxxl.out"); int a[101], b[101]; int main() { int n , m , t = 0; cin >> n; for(int i = 1 ; i <= n ; ++i)cin >> a[i]; for(int i = 1 ; i <= n / 2 ; ++i)swap(a[i] , a[n-i+1]); cin >> m; for(int j = 1 ; j <= m ; ++j)cin >> b[j]; for(int i = 1 ; i <= m / 2 ; ++i)swap(b[i] , b[m-i+1]); if(m > n) n = m; for(int i = 1 ; i <= n ; i++) { int c = a[i] + b[i] + t; a[i] = c % 10; t = c / 10; } if(t > 0) a[++n] = t; for(int i = n ; i >= 1 ; i--) cout << a[i]; return 0; }
#include<fstream>
using namespace std;
ifstream cin("sumaxxl.in");
ofstream cout("sumaxxl.out");
int a[101], b[101];
int main()
{
    int n , m , t = 0;
    cin >> n;
    for(int i = 1 ; i <= n ; ++i)cin >> a[i];
    for(int i = 1 ; i <= n / 2 ; ++i)swap(a[i] , a[n-i+1]);
    cin >> m;
    for(int j = 1 ; j <= m ; ++j)cin >> b[j];
    for(int i = 1 ; i <= m / 2 ; ++i)swap(b[i] , b[m-i+1]);
    if(m > n) n = m;
    for(int i = 1 ; i <= n ; i++)
    {
        int c = a[i] + b[i] + t;
        a[i] = c % 10;
        t = c / 10;
    }
    if(t > 0) a[++n] = t;
    for(int i = n ; i >= 1 ; i--) cout << a[i];
    return 0;
}
Comentarii

S-ar putea sa iti placa