SUMBIG - Tính tổng 2 số nguyên lớn

View as PDF

Submit solution

Points: 1.00 (partial)
Time limit: 1.0s
Memory limit: 256M

Author:
Problem type
Allowed languages
C, C#, C++, Go, Java, Pascal, Perl, PHP, PyPy, Python, Ruby, Rust, Scratch, Swift

Cho hai số nguyên không âm ~a~ và ~b~. Hãy tính ~a + b~.

Input

  • Dòng đầu chứa số ~a~.
  • Dòng sau chứa số ~b~.

Giới hạn:

  • ~0 ≤ a, b < 10^{1000000} (a, b\text{ có không quá }10^5\text{ chữ số})~

Output

  • Gồm một dòng duy nhất là kết quả của ~a + b~.

Sample

Input #1
123
4567
Output #1
4690
Input #2
1234567890
9879879876543219876
Output #2
9879879877777787766

Problem source: Chuyên Sơn La Online Judge


Comments

Please read the guidelines before commenting.



  • 0
    Chutecobac  commented on May 2, 2025, 4:38 a.m. edited

    include <bits/stdc++.h>

    using namespace std;

    const int maxVal = 1e6 + 5;

    void testcase() { char a[maxVal], b[maxVal]; cin >> a >> b; int doLonA = strlen(a), doLonB = strlen(b);

    if (doLonA<doLonB) { swap(a, b); swap(doLonA, doLonB); }

    int x[maxVal], y[maxVal]; for (int i=0; i<doLonA; i++) x[i] = a[doLonA - i - 1] - '0'; for (int i=0; i<doLonB; i++) y[i] = b[doLonB - i - 1] - '0'; for (int i=doLonB; i<doLonA; i++) y[i] = 0;

    int n = 0, du = 0, z[maxVal + 1]; for (int i=0; i<doLonA; i++) { int s = x[i] + y[i] + du; z[n++] = s % 10; du = s / 10; }

    if (du) z[n++] = du;

    for (int i=n-1; i>=0; i--) cout << z[i]; cout << endl; }

    int main() { ios::syncwithstdio(0); cin.tie(0); int t=1; for (int i=1; i<=t; i++) { testcase(); } return 0; } **


  • 0
    codec  commented on Jan. 1, 2025, 10:30 a.m.

    tại py k giới hạn , c++ thì nó có , nên phải khổ v đó b , luyện tư duy í


  • 0
    Tri1501_10Ti  commented on Oct. 15, 2024, 12:13 a.m.

    code c++ đi đừng xài py


  • -3
    kietjumper  commented on Sept. 26, 2024, 3:15 a.m.

    Python ko giới hạn số chữ số :))


  • -4
    bnbnbn  commented on Dec. 13, 2024, 2:23 p.m.

    cần m giúp ak thg ll


  • -1
    phong_tran1202  commented on Aug. 12, 2024, 2:16 p.m.

    python nhìn chỉ biết cười =))


  • 0
    haidang3004  commented on March 27, 2024, 3:22 p.m.

    python thì dễ mà sao c++ khó thế nhỉ


  • 0
    duydonv  commented on Jan. 21, 2024, 6:34 a.m.

    sao em lại sai đúng test case 8 thôi nhỉ, em code bằng c và dùng stack để cộng. Có ai code kiểu này không chỉ giáo em với


  • 0
    dinhvantung0611  commented on Jan. 4, 2024, 5:37 p.m.

    Code python có thể AC


  • -2
    triduc_2k9  commented on Dec. 23, 2023, 2:08 p.m.

    Khó quá


  • -1
    nvthang  commented on Nov. 22, 2023, 3:03 a.m.

    case 5 có bị sai test ko ạ


  • 0
    triphan2004  commented on Nov. 5, 2023, 4:22 p.m.

    Test case 9 là gì vậy mọi người