标签:ons sort algo https lan target cin 选择 tar
https://vjudge.net/problem/UVA-1610
题意:输入一个n个字符串的集合D,找一个长度最短的字符串S,使得D中恰好有一半串小于等于S,另一半串大于S。
思路:先拍序,然后选择中间的两个,比较他们就可以了。可以用枚举法来比较。
1 #include<string> 2 #include<iostream> 3 #include<algorithm> 4 using namespace std; 5 6 const int maxn = 1000 + 5; 7 8 string str[maxn]; 9 10 int main() 11 { 12 //freopen("D:\\txt.txt", "r", stdin); 13 int n; 14 while (cin >> n && n) 15 { 16 for (int i = 0; i < n; i++) 17 cin >> str[i]; 18 sort(str, str + n); 19 int x = n / 2 - 1; 20 int y = n / 2; 21 string ans = ""; 22 string cmp = ""; 23 int ok = 0; 24 int k = 0; 25 while (true) 26 { 27 for (char i = ‘A‘; i <= ‘Z‘; i++) 28 { 29 cmp = ans + i; 30 if (str[x] <= cmp && str[y] > cmp) 31 { 32 cout << cmp << endl; 33 ok = 1; 34 break; 35 } 36 37 } 38 if (ok) break; 39 ans = ans + str[x][k++]; 40 } 41 } 42 return 0; 43 }
标签:ons sort algo https lan target cin 选择 tar
原文地址:http://www.cnblogs.com/zyb993963526/p/6354217.html