Advertisement
Spocoman

04. Character Multiplier

Nov 22nd, 2023 (edited)
615
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.57 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int main() {
  6.     string str1, str2;
  7.     cin >> str1 >> str2;
  8.  
  9.     int len1 = str1.length(),
  10.         len2 = str2.length(),
  11.         minLen = len1 >= len2 ? len2 : len1,
  12.         maxLen = len1 >= len2 ? len1 : len2,
  13.         result = 0;
  14.  
  15.     for (size_t i = 0; i < minLen; i++) {
  16.         result += str1[i] * str2[i];
  17.     }
  18.  
  19.     if (len1 != len2) {
  20.         for (size_t i = minLen; i < maxLen; i++) {
  21.             result += (len1 > len2 ? str1[i] : str2[i]);
  22.         }
  23.     }
  24.  
  25.     cout << result << endl;
  26.     return 0;
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement