kolioi

01. Different Strings C++ Exam

Jan 22nd, 2019
173
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.75 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3.  
  4. int main()
  5. {
  6.     using namespace std;
  7.  
  8.     size_t len;
  9.     cin >> len;
  10.  
  11.     string str1, str2;
  12.     cin >> str1 >> str2;
  13.  
  14.     size_t num_diff = 0, sum_digits = 0;
  15.     for (size_t i = 0; i < len; ++i)
  16.     {
  17.         if (str1[i] == str2[i])
  18.             cout << str1[i];
  19.         else if (isalpha(str1[i]) && isalpha(str2[i]) && abs(str1[i] - str2[i]) == 32)
  20.             cout << __min(str1[i], str2[i]);
  21.         //else if (toupper(str1[i]) == toupper(str2[i]))
  22.         //  cout << (char)toupper(str1[i]);
  23.         else
  24.         {
  25.             cout << '#';
  26.             ++num_diff;
  27.         }
  28.         if (isdigit(str1[i]))
  29.             sum_digits += str1[i] - '0';
  30.         if (isdigit(str2[i]))
  31.             sum_digits += str2[i] - '0';
  32.     }
  33.  
  34.     cout << endl << num_diff << endl << len - num_diff << endl << sum_digits << endl;
  35.  
  36.     return 0;
  37. }
Advertisement
Add Comment
Please, Sign In to add comment