Skip to content

Instantly share code, notes, and snippets.

@prehistoricpenguin
Created March 17, 2015 10:59
Show Gist options
  • Save prehistoricpenguin/305f79707256948e5924 to your computer and use it in GitHub Desktop.
Save prehistoricpenguin/305f79707256948e5924 to your computer and use it in GitHub Desktop.
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
#include <unordered_map>
#include <limits>
#include <map>
#include <iterator>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
int main() {
std::vector<std::string> vec_str;
int cases;
std::cin >> cases;
char buf[257];
// ignore all \n
std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
int min_len = std::numeric_limits<int>::max();
for (int i = 0; i < cases; ++i) {
std::string tmp;
int len = tmp.length();
min_len = std::min(len, min_len);
vec_str.push_back(std::move(tmp));
}
std::string ans;
for (int i = 0; i < min_len; ++i) {
char ch = 0;
for (int j = 0; j < cases; ++j) {
int idx = vec_str[j].length() -1 - i;
char cur = vec_str[j][idx];
if (ch == 0) {
ch = cur;
} else {
if (ch != cur) {
goto out;
}
}
}
ans += ch;
}
out:
std::reverse(std::begin(ans), std::end(ans));
if (!ans.length()) {
std::cout << "nai" << std::endl;
} else {
std::cout << ans << std::endl;
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment