PTA 7-15 航空公司VIP客户查询
2017-10-25 00:51
375 查看
不少航空公司都会提供优惠的会员服务,当某顾客飞行里程累积达到一定数量后,可以使用里程积分直接兑换奖励机票或奖励升舱等服务。现给定某航空公司全体会员的飞行记录,要求实现根据身份证号码快速查询会员里程积分的功能。
#include <cstdio> #include <cstring> #include <iostream> #include <algorithm> using namespace std; const int maxn = 1e6 + 10; const int maxsize = 15; struct Trie { int tot, child[maxn][maxsize]; int val[maxn]; void init() { tot = 0; memset(child[0], -1, sizeof(child[0])); memset(val, 0, sizeof(val)); } void Insert(char *s, int v) { int root = 0; for (int i = 0; s[i]; i++) { int index; if (s[i] == 'x' || s[i] == 'X') index = 10; else index = s[i] - '0'; int u = child[root][index]; if (u == -1) { u = ++tot; memset(child[u], -1, sizeof(child[u])); child[root][index] = u; } root = u; } val[root] += v; } int Query(char *s) { int root = 0; for (int i = 0; s[i]; i++) { int index; if (s[i] == 'x' || s[i] == 'X') index = 10; else index = s[i] - '0'; int u = child[root][index]; if (u == -1) return -1; root = u; } return val[root]; } }trie; int main() { trie.init(); char str[20]; int n, k, x; scanf("%d %d", &n, &k); for (int i = 1; i <= n; i++) { scanf("%s%d", str, &x); if (x < k) x = k; trie.Insert(str, x); } int q; scanf("%d", &q); for (int i = 1; i <= q; i++) { scanf("%s", str); x = trie.Query(str); if (x != -1) printf("%d\n", x); else printf("No Info\n"); } }
相关文章推荐
- PTA 7-15(查找) 航空公司VIP客户查询(25 分) 25分代码 哈希方法
- PTA 7-45 航空公司VIP客户查询(25 分)map查找应用
- 7-15(查找) 航空公司VIP客户查询(25 分)
- PTA-数据结构 5-45 航空公司VIP客户查询 (25分)
- PAT DS 506 航空公司VIP客户查询
- PAT 航空公司VIP客户查询 (哈希 | map) -- 解题报告
- 航空公司VIP客户查询
- PAT5-06. 航空公司VIP客户查询
- 5-45 航空公司VIP客户查询 (25分) HASH
- 航空公司VIP客户查询
- 航空公司VIP客户查询【PAT】
- 5-45 航空公司VIP客户查询 (25分)
- 航空公司VIP客户查询(25 分)(Hash)
- 9、客户模块之按条件查询(异步查询客户级别后台代码编写)
- 数据库复习总结(15)-子查询(分页)
- MongoDB小结15 - find【查询条件$ne】
- 查询某个客户最新的两个订单
- 15.数据库原理 事务的原理,锁机制,表连接,复杂查询语句(工作经验),性能调优,锁表以及解决方案==
- 查询客户的SQL
- 15、sql语句集,Linux 下PHP查询mysql