1. 程式人生 > >1016 部分A+B

1016 部分A+B

numa a+b name pre itl names main tps stream

題目鏈接:https://pintia.cn/problem-sets/994805260223102976/problems/994805306310115328

題解:

 1 #include <iostream>
 2 #include<string>
 3 using namespace std;
 4 
 5 int main() {
 6     string A, B;
 7     int DA, DB;
 8     cin >> A >> DA >> B >> DB;
 9     int nDA = 0, nDB = 0;
10
for (int i = 0; i < A.size(); i++) 11 if (A[i] - 48 == DA) 12 nDA++; 13 for (int i = 0; i < B.size(); i++) 14 if (B[i] - 48 == DB) 15 nDB++; 16 17 int numA = 0, numB = 0, a = 1, b = 1; 18 for (int i = 0; i < nDA; i++) { 19 numA += a * DA;
20 a *= 10; 21 } 22 for (int i = 0; i < nDB; i++) { 23 numB += b * DB; 24 b *= 10; 25 } 26 cout << numA + numB; 27 return 0; 28 }

1016 部分A+B