250
const string V = "aiueo";
bool is_v(char c)
{
return V.find( c ) != string::npos;
}
class VowelEncryptor {
public:
vector <string> encrypt(vector <string> t) {
for(int i=0; i<t.size(); ++i){
bool flg = true;
for(int j=0; flg && j<t[i].size(); ++j){
flg = is_v( t[i][j] );
}
if( flg )continue;
string s;
for(int j=0; j<t[i].size(); ++j){
if( !is_v( t[i][j] ) )s += t[i][j];
}
t[i] = s;
}
return t;
}
};
500
set<int> make_D(void)
{
set<int> s;
for(int i=0; i<9*4; ++i){
s.insert( i + 1 );
}
return s;
}
set<int> make_I(void)
{
set<int> s;
int r = 1;
while( s.size() < 9*4 ){
s.insert(r * 10 + 1);
s.insert(r * 10 + 3);
s.insert(r * 10 + 4);
s.insert(r * 10 + 6);
++r;
}
return s;
}
class RailroadSeatNumeration {
public:
string getInternational(vector <int> t) {
set<int> I = make_I();
set<int> D = make_D();
bool a = true;
bool b = true;
for(int i=0; i<t.size(); ++i){
a = a && I.count( t[i] );
b = b && D.count( t[i] );
}
if(a && b)return "AMBIGUOUS";
if( !a && !b )return "BAD DATA";
ostringstream oss;
for(int i=0; i<t.size(); ++i){
if(i) oss << ' ';
if( a ) oss << t[i];
else{
set<int>::iterator a = D.find( t[i] );
int d = distance( D.begin(), a );
set<int>::iterator b = I.begin();
while( d-- )++b;
oss << *b;
}
}
return oss.str();
}
};
1000
class ProbabilisticTranslator {
public:
int maximumFidelity(vector <string> s, vector <string> dic, vector <string> freq) {
{
vector<string> t;
for(int i=0; i<s.size(); ++i){
istringstream iss( s[i] );
for(string u; iss >> u; t.push_back(u));
}
s = t;
}
int W = 0;
map< string, vector<string> > conv;
for(int i=0; i<dic.size(); ++i){
istringstream iss( dic[i] );
string a, b;
char c;
for( iss >> a >> c; iss >> b; conv[a].push_back(b) );
W = max(W, (int)conv[a].size());
}
map< pair<string, string>, int > value;
for(int i=0; i<freq.size(); ++i){
istringstream iss( freq[i] );
string a, b;
int c;
iss >> a >> b >> c;
value[ make_pair(a, b) ] = c;
}
const int size = s.size()+1;
int t[size][W];
fill( &t[0][0], &t[size-1][W], -1 );
for(int i=0; i<conv[ s[0] ].size(); ++i){
t[0][i] = 0;
}
for(int i=0; i+1<s.size(); ++i){
for(int j=0; j<W; ++j){
if( t[i][j] == -1 )continue;
for(int k=0; k<conv[ s[i+1] ].size(); ++k){
string a = conv[ s[i] ][j];
string b = conv[ s[i+1] ][k];
int v = value[ make_pair(a, b) ];
t[i+1][k] = max(t[i+1][k], t[i][j] + v);
}
}
}
return *max_element( &t[0][0], &t[size-1][W] );
}
};
0 件のコメント :
コメントを投稿