码迷,mamicode.com
首页 > 编程语言 > 详细

hihocoder1712 字符串排序(思维)

时间:2018-04-30 01:04:44      阅读:162      评论:0      收藏:0      [点我收藏+]

标签:out   efi   顺序表   根据   style   return   false   problems   strlen   

https://hihocoder.com/problemset/problem/1712

感觉解法呼之欲出,却出不来。。

一个很好的思路是,根据新的顺序表,把给定的n组字符串换成旧表对应的字符,然后用strcmp

 1 #include<iostream>
 2 #include<cstdio>
 3 #include<queue>
 4 #include<cstring>
 5 #include<algorithm>
 6 #include<cmath>
 7 #include<map>
 8 #define lson l, m, rt<<1
 9 #define rson m+1, r, rt<<1|1
10 #define IO ios::sync_with_stdio(false);cin.tie(0);
11 #define INF 0x3f3f3f3f
12 typedef long long ll;
13 using namespace std;
14 int n;
15 char str[30];
16 map<char, int> mp;
17 typedef struct{
18     char s1[110];
19     char s2[110];
20 }Node;
21 Node node[1010];
22 bool cmp(const Node a, const Node b)
23 {
24     return strcmp(a.s2, b.s2)<0;
25 }
26 int main()
27 {
28     cin >> n;
29     cin >> str;
30     for(int i = 0; i < n; i++){
31         cin >> node[i].s1;
32     } 
33     for(int i = 0; i < 26; i++){
34         mp[str[i]] = i;
35     }
36     for(int i = 0; i < n; i++){
37         for(int j = 0; j < strlen(node[i].s1); j++){
38             node[i].s2[j] = mp[node[i].s1[j]]+a;
39         }
40     }
41     sort(node, node+n, cmp);
42     for(int i = 0; i < n; i++){
43         cout << node[i].s1 << endl;
44     }
45     return 0;
46 } 

 

hihocoder1712 字符串排序(思维)

标签:out   efi   顺序表   根据   style   return   false   problems   strlen   

原文地址:https://www.cnblogs.com/Surprisezang/p/8972413.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!