sicily 1198

全排+排序

#include <iostream> #include <cstring> #include <string> #include <set> using namespace std; string s[8]; int n; set<string> data; bool isVis[8]; string sub; void combin(int cur) { if(cur == n) { data.insert(sub); return; } for(int i = 0; i < n; i++) { if(!isVis[i]) { int beg = sub.size(); sub += s[i]; isVis[i] = true; combin(cur + 1); sub.erase(beg, sub.size()); isVis[i] = false; } } } int main() { int cases; cin >> cases; while(cases--) { cin >> n; sub.clear(); memset(isVis, false, sizeof(isVis)); data.clear(); for(int i = 0; i < n; i++) cin >> s[i]; combin(0); cout << *(data.begin()) << endl;; } return 0; } 

你可能感兴趣的:(String,stdstring)