PTA 7-15 航空公司VIP客户查询

网友投稿 901 2022-11-28

PTA 7-15 航空公司VIP客户查询

PTA 7-15 航空公司VIP客户查询

不少航空公司都会提供优惠的会员服务,当某顾客飞行里程累积达到一定数量后,可以使用里程积分直接兑换奖励机票或奖励升舱等服务。现给定某航空公司全体会员的飞行记录,要求实现根据身份证号码快速查询会员里程积分的功能。

#include #include #include #include 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"); }}

版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:UVA - 1543 Telescope——最优三角剖分
下一篇:POJ 3140 Contestants Division——树形dp
相关文章

 发表评论

暂时没有评论,来抢沙发吧~