解いた問題

5/21/2012

SRM402 Div2 Easy

250

やるだけ



class WordAbbreviation {
public:
  vector <string> getAbbreviations(vector <string> ws)
  {   
    const int size = ws.size();
    vector <string> v(size);

    while (true) {
      map<string, int> cnt;
      for (int i = 0; i < (int)size; ++i) {
        ++cnt[v[i]];
      }
      cnt.erase("");
      if (cnt.size() == size) break;
      for (int i = 0; i < (int)size; ++i) {
        if (cnt[v[i]] != 1) v[i] += ws[i][v[i].size()];
      }
    }

    return v;
  }
};