ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#187656 | #1. A+B Problem | darksoul | 100 | 0ms | 1212kb | C++11 | 2.6kb | 2023-10-02 11:52:08 | 2023-10-02 11:52:10 |
answer
#include <bits/stdc++.h>
using namespace std;
int n = 10;
string a,b;
int cnt(char a,char b)
{
return (a <= '9' ? a - '0' : a - 55) + (b <= '9' ? b - '0' : b - 55);
}
string count(string a,string b)
{
if (b.size() > a.size())
swap(a,b);
b = string(a.size() - b.size(),'0') + b;
string ans = "";
int p = 0;
for (int i = a.size() - 1; i >= 0; i--)
{
int x = cnt(a[i],b[i]) + p,y = x % n;
ans = char(y > 9 ? 55 + y : y + '0') + ans,p = x / n;
}
if (p)
ans = '1' + ans;
return ans;
}
string count2(string a,string b)
{
if (b.size() > a.size())
swap(a,b);
b = string(a.size() - b.size(),'0') + b;
string ans = "";
int p = 0;
for (int i = a.size() - 1; i >= 0; i--)
{
int x = cnt(a[i],b[i]) + p,y = x % n;
ans = char(y > 9 ? 55 + y : y + '0') + ans,p = x / n;
}
if (p)
ans = '1' + ans;
return ans;
}
string count3(string a,string b)
{
if (b.size() > a.size())
swap(a,b);
b = string(a.size() - b.size(),'0') + b;
string ans = "";
int p = 0;
for (int i = a.size() - 1; i >= 0; i--)
{
int x = cnt(a[i],b[i]) + p,y = x % n;
ans = char(y > 9 ? 55 + y : y + '0') + ans,p = x / n;
}
if (p)
ans = '1' + ans;
return ans;
}
string count4(string a,string b)
{
if (b.size() > a.size())
swap(a,b);
b = string(a.size() - b.size(),'0') + b;
string ans = "";
int p = 0;
for (int i = a.size() - 1; i >= 0; i--)
{
int x = cnt(a[i],b[i]) + p,y = x % n;
ans = char(y > 9 ? 55 + y : y + '0') + ans,p = x / n;
}
if (p)
ans = '1' + ans;
return ans;
}
string count5(string a,string b)
{
if (b.size() > a.size())
swap(a,b);
b = string(a.size() - b.size(),'0') + b;
string ans = "";
int p = 0;
for (int i = a.size() - 1; i >= 0; i--)
{
int x = cnt(a[i],b[i]) + p,y = x % n;
ans = char(y > 9 ? 55 + y : y + '0') + ans,p = x / n;
}
if (p)
ans = '1' + ans;
return ans;
}
string count6(string a,string b)
{
if (b.size() > a.size())
swap(a,b);
b = string(a.size() - b.size(),'0') + b;
string ans = "";
int p = 0;
for (int i = a.size() - 1; i >= 0; i--)
{
int x = cnt(a[i],b[i]) + p,y = x % n;
ans = char(y > 9 ? 55 + y : y + '0') + ans,p = x / n;
}
if (p)
ans = '1' + ans;
return ans;
}
string count7(string a,string b)
{
if (b.size() > a.size())
swap(a,b);
b = string(a.size() - b.size(),'0') + b;
string ans = "";
int p = 0;
for (int i = a.size() - 1; i >= 0; i--)
{
int x = cnt(a[i],b[i]) + p,y = x % n;
ans = char(y > 9 ? 55 + y : y + '0') + ans,p = x / n;
}
if (p)
ans = '1' + ans;
return ans;
}
int main()
{
cin >> a >> b;
cout << count(a,b);
return 0;
}
详细
小提示:点击横条可展开更详细的信息
Test #1:
score: 10
Accepted
time: 0ms
memory: 1212kb
input:
23 24
output:
47
result:
ok 1 number(s): "47"
Test #2:
score: 10
Accepted
time: 0ms
memory: 1208kb
input:
233 1
output:
234
result:
ok 1 number(s): "234"
Test #3:
score: 10
Accepted
time: 0ms
memory: 1208kb
input:
222 333
output:
555
result:
ok 1 number(s): "555"
Test #4:
score: 10
Accepted
time: 0ms
memory: 1208kb
input:
1 333
output:
334
result:
ok 1 number(s): "334"
Test #5:
score: 10
Accepted
time: 0ms
memory: 1212kb
input:
222 333
output:
555
result:
ok 1 number(s): "555"
Test #6:
score: 10
Accepted
time: 0ms
memory: 1212kb
input:
242 333
output:
575
result:
ok 1 number(s): "575"
Test #7:
score: 10
Accepted
time: 0ms
memory: 1208kb
input:
222 3330
output:
3552
result:
ok 1 number(s): "3552"
Test #8:
score: 10
Accepted
time: 0ms
memory: 1212kb
input:
2220 333
output:
2553
result:
ok 1 number(s): "2553"
Test #9:
score: 10
Accepted
time: 0ms
memory: 1208kb
input:
222 555
output:
777
result:
ok 1 number(s): "777"
Test #10:
score: 10
Accepted
time: 0ms
memory: 1208kb
input:
222 3333
output:
3555
result:
ok 1 number(s): "3555"
Extra Test:
score: 0
Extra Test Passed