Advertisement
AmidamaruZXC

TaskL

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