You are viewing a single comment's thread. Return to all comments →
A nice and easy solution in C++11/14 that doesn't use any built-in function: (bit field for the elements)
#include <iostream> #include <string> using namespace std; int main() { int N, elements = 0x7FFFFFFF, result = 0; string s; cin >> N; while (N--) { cin >> s; int current = 0; for (char c : s) current |= 1 << (c - 'a'); elements &= current; } for (; elements; elements = elements & (elements - 1)) ++result; cout << result << endl; return 0; }
Seems like cookies are disabled on this browser, please enable them to open this website
Gemstones
You are viewing a single comment's thread. Return to all comments →
A nice and easy solution in C++11/14 that doesn't use any built-in function: (bit field for the elements)