My issue
include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
unordered_map<char, int> mp;
for (int i = 0; i <= n; i++) {
string str;
cin >> str;
unordered_set<char> st;
for (int j = 0; j < str.size(); j++) st.insert(str[j]);
for (auto it : st) mp[it]++;
}
string ans;
for (auto it : mp) if (it.second == n) ans.push_back(it.first);
if (ans.size() == 0) ans = "no such string";
else sort(ans.begin(),ans.end());
cout << ans << endl;
return 0;
}
My code
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
unordered_map<char, int> mp;
for (int i = 0; i <= n; i++) {
string str;
cin >> str;
unordered_set<char> st;
for (int j = 0; j < str.size(); j++) st.insert(str[j]);
for (auto it : st) mp[it]++;
}
string ans;
for (auto it : mp) if (it.second == n) ans.push_back(it.first);
if (ans.size() == 0) ans = "no such string";
else sort(ans.begin(),ans.end());
cout << ans << endl;
return 0;
}
Problem Link: Subanagrams Practice Coding Problem