PKU 3602 Typographical Ligatures

http://poj.org/problem?id=3602
入力される文字列を表すのに必要な文字種類数を求めろというような問題。

setにつっこみました

main(){
  string in,str;
  while(getline(cin,str))in+=str;

  string key[]={"ffi","ffl","ff","fl","fi","''","``"};

  set<string> app;
  for(int i=0;i<SZ(in);++i){
    if(isspace(in[i]))continue;
    bool fi=false;
    for(int j=0;j<7;++j)
      if(in.substr(i,SZ(key[j]))==key[j]){
        app.insert(key[j]);
        fi=true;
        i+=SZ(key[j])-1;
        break;
      }
    if(fi)continue;
    app.insert(in.substr(i,1));
  }
  cout<<SZ(app)<<endl;
}