Points:
200 (p)
Time limit:
1.0s
Memory limit:
256M
Input:
stdin
Output:
stdout
Tính tổng của 2 số nguyên \(a\) và \(b\).
Input
- Gồm 2 dòng là 2 số nguyên \(a\) và \(b\) \((a, b \leq 10^{255})\)
Output
- Gồm 1 dòng là tổng \(a+b\)
Example
Test 1
Input
2
5
Output
7
Test 2
Input
123456789123456789123
1
Output
123456789123456789124
Comments
quá giới hạn long long rồi ;-;
.
ôi bài này khó quá e ko bt lm
code c++ nộp 1 tỷ lần mới đúng :>
code c++
include<bits/stdc++.h>
using namespace std;
string a,b,s;
int x=0;
int main(){
cin>>a>>b;
int mx=max(a.size(),b.size());
while(a.size()>b.size()) b='0'+b;
while(a.size()<b.size()) a='0'+a; for(int i=mx-1;i>=0;i--){
int m=(a[i]-'0')+(b[i]-'0')+x;
if(m>=10)
x=1;
else x=0;
s+=to_string(m%10);
}
if((a[0]-'0')+(b[0]-'0')>=10)
cout<<1;
for(int i=s.size()-1;i>=0;i--)
cout<<s[i];
}
Cho bài này ở phần từ dễ đến khó ở đầu tiên đi , thích hợp cho người mới vào web này
var
a, b, r: string;
i, carry, temp, sum: integer;
function SumLargeNumbers(a, b: string): string;
var
lenA, lenB, i, carry, sum: integer;
r: string;
begin
lenA := Length(a);
lenB := Length(b);
if lenB > lenA then
begin
r := a;
a := b;
b := r;
end;
end;
begin
end.
code tham khảo pascal nhé đừng cop ko là đi ây
Sao lại có người wa nhỉ
This comment is hidden due to too much negative feedback. Click here to view it.
ae cần code c++ nhắn tin cho tôi nhé ko cần cảm ơn đâu!!!
27 more comments