Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- using namespace std;
- const int MAX_CHAR = 26;
- void commonCharacters(string str[], int n)
- {
- bool prim[MAX_CHAR];
- int k = 0;
- memset(prim, true, sizeof(prim));
- for (int i = 0; i < n; i++)
- {
- bool sec[MAX_CHAR] = { false };
- for (int j = 0; str[i][j]; j++)
- if (prim[str[i][j] - 'a'])
- sec[str[i][j] - 'a'] = true;
- memcpy(prim, sec, MAX_CHAR);
- }
- for (int i = 0; i < 26; i++)
- if (prim[i])
- cout << char(i + 'a') << " ";
- else
- k++;
- if (k == 26)
- cout << "NO COMMON CHARACTERS";
- }
- int main()
- {
- int n;
- cin >> n;
- string* arr = new string[n];
- for (int i = 0; i < n; i++)
- cin >> arr[i];
- commonCharacters(arr, n);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement