@wsndy-xx
2018-05-05T03:24:20.000000Z
字数 839
阅读 1103
wsndy
18.05.04
题解定义新的字符字典序大小
然后给出 个字符串
按照新的字典序排序后从小到大输出
其实不需要重新定义(应该也没法重新定义)
只需将新的字典序映射到原先的字典序中
就是将每个字符串 映射出一个
例如
新的字典序 bdceafghijklmnopqrstuvwxyz字符 S = abcde
那么 的 为
eacbd
那么只需按照 的大小排序后
输出 即可
#include <iostream>#include <cstdio>#include <algorithm>const int N = 1010;int Map[30], n;struct Node {std:: string ture_string, map_string;}E[N];std:: string A;inline bool cmp(Node a, Node b) {return a.map_string < b.map_string;}int main() {std:: cin >> n;std:: cin >> A;for(int i = 1; i <= n; i ++) std:: cin >> E[i].ture_string;int Len = A.length();for(int i = 0; i < Len; i ++) Map[A[i] - 'a' + 1] = i + 1;for(int i = 1; i <= n; i ++) {int L = E[i].ture_string.length();for(int j = 0; j < L; j ++)E[i].map_string += Map[E[i].ture_string[j] - 'a' + 1] + 'a' - 1;}std:: cout << E[1].map_string;std:: sort(E + 1, E + n + 1, cmp);for(int i = 1; i <= n; i ++) std:: cout << E[i].ture_string << "\n";return 0;}