yokobuttonの不定期で競技プログラミングをするブログ

不定期で解けた競技プログラミングコンテストの問題を載せています。

AtCoder Beginner Contest 225 A - Distinct Strings

問題の要約
 英小文字のみからなる長さ3の文字列Sが与えられる。
 Sの各文字を並び替えて得られる文字列は,何種類あるか?
制約
 Sは英小文字のみからなる長さ3の文字列

入力
 S

考え方
 1,これは同じものがある順列である。
 2,順列はC++ではnext_permutationで生成できる。
 3,長さ3の文字列なのでせいぜい3!=3*2*1=6より,計算量も大丈夫そう。
 4これで実装してみる。 

#include<iostream>
#include<algorithm>
#include<string>

using namespace std;

int main(){
  string S;
  cin >> S;
  int count = 0;
  sort(S.begin(), S.end());
  do{
    count++;
  }while(next_permutation(S.begin(), S.end()));
  
  cout << count << endl;
  
  return 0;
}