Skip to content

Commit b5a57d5

Browse files
authored
T : o
1 parent 7a099ed commit b5a57d5

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#include <bits/stdc++.h>
2+
using namespace std;
3+
4+
vector<string> solution(vector<string> orders, vector<int> course) {
5+
vector<string> answer;
6+
7+
for(int n : course){
8+
//cout << "-------------------" << endl;
9+
unordered_map<string,int> cnt;
10+
for(auto order : orders){
11+
if(n > order.size()) continue;
12+
vector<int> cb(order.size(),1);
13+
for(int i=0;i<order.size()-n;i++) cb[i] = 0;
14+
do{
15+
string conbi;
16+
for(int i=0;i<order.size();i++){
17+
if(!cb[i]) continue;
18+
conbi += order[i];
19+
}
20+
sort(conbi.begin(),conbi.end());
21+
cnt[conbi]++;
22+
}while(next_permutation(cb.begin(),cb.end()));
23+
}
24+
int mx = 1;
25+
for(auto iter : cnt){
26+
//cout << iter.first << " " << iter.second << endl;
27+
if(mx < iter.second){
28+
mx = iter.second;
29+
}
30+
}
31+
//cout << mx << endl;
32+
if(mx < 2) continue;
33+
for(auto iter : cnt){
34+
if(mx == iter.second){
35+
answer.push_back(iter.first);
36+
}
37+
}
38+
}
39+
sort(answer.begin(),answer.end());
40+
return answer;
41+
}

0 commit comments

Comments
 (0)