回答編集履歴

1

修正

2018/01/20 10:16

投稿

episteme
episteme

スコア16614

test CHANGED
@@ -7,6 +7,8 @@
7
7
  #include <iostream>
8
8
 
9
9
  #include <algorithm>
10
+
11
+ #include <set>
10
12
 
11
13
  #include <string>
12
14
 
@@ -18,15 +20,11 @@
18
20
 
19
21
  bool contains_str(const std::string& str, const std::string& target) {
20
22
 
21
- std::string tgt_ = target;
23
+ // targetに含まれる文字をそれぞれ一つ含み、sortされた文字集合tgtを作る。
22
24
 
23
- // targetに含まれる文字をそれぞれ一つ含み、sortされた文字集合tgt_を作る。
25
+ std::set<char> tgt(target.begin(), target.end());
24
26
 
25
- std::sort(tgt_.begin(), tgt_.end());
26
-
27
- tgt_.erase(std::unique(tgt_.begin(),tgt_.end()), tgt_.end());
28
-
29
- // strがtgt_の全要素を包含するならtrue
27
+ // strがtgtを包含するならtrue
30
28
 
31
29
  return std::includes(str.begin(), str.end(), tgt_.begin(), tgt_.end());
32
30
 
@@ -76,6 +74,4 @@
76
74
 
77
75
  */
78
76
 
79
-
80
-
81
77
  ```