ICPC国内予選模擬2015 B 空港コード
問題
方針
指示通りに空港名を変換した後,切るところを全探索する.
実装
#include <iostream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
using namespace std;
#define loop(i,a,b) for(int i=(a);i<int(b);i++)
#define rep(i,b) loop(i,0,b)
bool isb(char c){
if(c == 'a') return true;
if(c == 'i') return true;
if(c == 'u') return true;
if(c == 'e') return true;
if(c == 'o') return true;
return false;
}
string f(string s){
string res;
res += s[0];
for(int i=1;i<int(s.size());i++){
if(isb(s[i-1])) res += s[i];
}
return res;
}
int main(){
int n;
while(cin >> n && n){
int mlen = 0;
vector<string> ss(n);
vector<string> sname(n);
rep(i,n){
cin >> ss[i];
sname[i] = f(ss[i]);
mlen = max<int>(mlen, ss[i].size());
}
int ans = -1;
rep(i,mlen+1)if(i){
set<string> S;
rep(j,n) S.emplace(sname[j].substr(0,i));
if((int)S.size() == n){
ans = i;
break;
}
}
cout << ans << endl;
}
}