Advertisement
AmidamaruZXC

TaskL

Apr 24th, 2021
769
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.71 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3.  
  4. using namespace std;
  5.  
  6. const int MAX_CHAR = 26;
  7.  
  8. void commonCharacters(string str[], int n)
  9. {
  10.     bool prim[MAX_CHAR];
  11.     int k = 0;
  12.     memset(prim, true, sizeof(prim));
  13.  
  14.     for (int i = 0; i < n; i++)
  15.     {
  16.         bool sec[MAX_CHAR] = { false };
  17.  
  18.         for (int j = 0; str[i][j]; j++)
  19.             if (prim[str[i][j] - 'a'])
  20.                 sec[str[i][j] - 'a'] = true;
  21.         memcpy(prim, sec, MAX_CHAR);
  22.     }
  23.  
  24.     for (int i = 0; i < 26; i++)
  25.         if (prim[i])
  26.             cout << char(i + 'a') << " ";
  27.         else
  28.             k++;
  29.     if (k == 26)
  30.         cout << "NO COMMON CHARACTERS";
  31. }
  32.  
  33. int main()
  34. {
  35.     int n;
  36.     cin >> n;
  37.     string* arr = new string[n];
  38.     for (int i = 0; i < n; i++)
  39.         cin >> arr[i];
  40.     commonCharacters(arr, n);
  41.  
  42. }
  43.  
  44.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement