题目
代码
int da = 0, db = 0, an = 0, bn = 0, pa = 0, pb = 0;
string a, b;
cin >> a >> da >> b >> db;
for (int i = 0; i < a.length(); i++)
{
if (a[i] - 48 == da)
++an;
}
for (int i = 0; i < b.length(); i++)
{
if (b[i] - 48 == db)
++bn;
}
for (int i = 0; i < an; i++)
{
int t = da;
for (int j = 0; j < i; j++)
t *= 10;
pa += t;
}
for (int i = 0; i < bn; i++)
{
int t = db;
for (int j = 0; j < i; j++)
t *= 10;
pb += t;
}
cout << pa + pb;
return;
记录
比较偏好使用string
记录大额数字或者需要进行单独拆分的工作,但会比int
更慢把