6170: 部分A+B (15)
时间限制: 1 Sec 内存限制: 32 MB
献花: 102 解决: 96
[献花][花圈][TK题库]
题目描述
正整数A的“DA(为1位整数)部分”定义为由A中所有DA组成的新整数PA。例如:给定A = 3862767,DA = 6,则A的“6部分”PA是66,因为A中有2个6。
现给定A、DA、B、DB,请编写程序计算PA + PB。
输入
输入在一行中依次给出A、DA、B、DB,中间以空格分隔,其中0 < A, B < 1010。
输出
在一行中输出PA + PB的值。
样例输入
3862767 6 13530293 3
3862767 1 13530293 8
样例输出
399
0
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main()
{
#ifdef _DEBUG
ifstream cin("data.txt");
#endif // _DEBUG
string A, B;
int NewA, NewB;
int Da, Db;
while (cin >> A >> Da >> B >> Db)
{
NewA = 0, NewB = 0;
int StrLen = A.length();
for (int i = 0; i < StrLen; ++i)
{
if (A[i] - '0' == Da) { NewA = 10 * NewA + Da; }
}
StrLen = B.length();
for (int i = 0; i < StrLen; ++i)
{
if (B[i] - '0' == Db) { NewB = 10 * NewB + Db; }
}
cout << NewA + NewB << endl;
}
#ifdef _DEBUG
cin.close();
system("pause");
#endif // _DEBUG
return 0;
}