2009-01-09
SRM374 Div1 Easy: SyllableSorting
275点問題。
System Testで{"baqibae","baebaqi"}で落ちる。結果の並び順について問題がちゃんと読めていなかった故。
class SyllableSorting {
int vowelp(int c){ /// ← 返り値の型はboolでいい。intでもいいけど。ていうかpって何ww
switch(c){
case 'a':case 'e':case 'i':case 'o':case 'u': return true;
default: return false;
}
}
vector<string> parse(string s){
vector<string> res;
int st=1,l=sz(s),b=0;
for(int i=0;i<l;i++){
if(vowelp(s[i])){
st=2;
}else{
if(st==2){
res.pb(s.substr(b,i-b));
b=i;
st=1;
}
}
}
if(b<l) res.pb(s.substr(b));
return res;
}
public:
vector<string> sortWords(vector<string> words) {
int n=sz(words);
vector<pair<vector<string>,pair<vector<string>,string> > > res(n);
rep(i,n){
vector<string> syls=parse(words[i]);
vector<string> sorted(all(syls));
sort(all(sorted));
res[i]=make_pair(sorted,make_pair(syls,words[i]));
}
sort(all(res));
vector<string> ans(n);
rep(i,n) ans[i]=res[i].second.second;
return ans;
}
};
コメント
トラックバック - https://topcoder-g-hatena-ne-jp.jag-icpc.org/n4_t/20090109