mstoyanov7

3ta retake

May 24th, 2021
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.09 KB | None | 0 0
  1. #include <iostream>
  2. #include <array>
  3. #include <cctype>
  4.  
  5. const int maxSize = 150;
  6.  
  7. std::array<char, maxSize> readInput(int& textSize) {
  8. std::array<char, maxSize> arr{};
  9. for (int i = 0; i < textSize; ++i) {
  10. std::cin >> arr[i];
  11. }
  12. return arr;
  13. }
  14.  
  15. void Solution(std::array<char, maxSize>& textOne, std::array<char, maxSize>& textTwo, int& textSize) {
  16. int differences = 0;
  17.  
  18. for (int i = 0; i < textSize; ++i) {
  19.  
  20. if (textOne[i] == textTwo[i]) {
  21. std::cout << textOne[i];
  22. }
  23.  
  24. else if (std::abs(textOne[i] - textTwo[i]) == 32 && !ispunct(textOne[i]) && !ispunct(textTwo[i])) {
  25. if (isalpha(textOne[i])) {
  26. std::cout << textTwo[i];
  27. }
  28. else if (isalpha(textTwo[i])) {
  29. std::cout << textOne[i];
  30. }
  31. }
  32.  
  33. else if (textOne[i] != textTwo[i]) {
  34. std::cout << '!';
  35. differences++;
  36. }
  37. }
  38. std::cout << std::endl;
  39. std::cout << differences;
  40. }
  41.  
  42. int main() {
  43. int textSize;
  44. std::cin >> textSize;
  45.  
  46. std::array<char, maxSize> textOne = readInput(textSize);
  47. std::array<char, maxSize> textTwo = readInput(textSize);
  48.  
  49. Solution(textOne, textTwo, textSize);
  50. }
Advertisement
Add Comment
Please, Sign In to add comment