7-16 航空公司VIP客户查询(25 分)
不少航空公司都会提供优惠的会员服务,当某顾客飞行里程累积达到一定数量后,可以使用里程积分直接兑换奖励机票或奖励升舱等服务。现给定某航空公司全体会员的飞行记录,要求实现根据身份证号码快速查询会员里程积分的功能。
输入格式:
输入首先给出两个正整数N(≤105)和K(≤500)。其中K是最低里程,即为照顾乘坐短程航班的会员,航空公司还会将航程低于K公里的航班也按K公里累积。随后N行,每行给出一条飞行记录。飞行记录的输入格式为:18位身份证号码(空格)飞行里程
。其中身份证号码由17位数字加最后一位校验码组成,校验码的取值范围为0~9和x共11个符号;飞行里程单位为公里,是(0, 15 000]区间内的整数。然后给出一个正整数M(≤105),随后给出M行查询人的身份证号码。
输出格式:
对每个查询人,给出其当前的里程累积值。如果该人不是会员,则输出No Info
。每个查询结果占一行。
输入样例:
4 500
330106199010080419 499
110108198403100012 15000
120104195510156021 800
330106199010080419 1
4
120104195510156021
110108198403100012
330106199010080419
33010619901008041x
输出样例:
800
15000
1000
No Info
真的是超级感动的!!做这题做了好久好久!!至少隔了好久才写出了这题,刚开始指针各种飞输入都输入不了,后来在hbz的帮助终于不瞎飞了
nice 刚开始用 map水 水不了,只能用hash 嗯hash采用的是18位全部都要
上代码:
#include<iostream> #include<cstdio> #include<cstring> #include<algorithm> using namespace std; const long long maxn=1e5+7; typedef struct node* Node; typedef long long ll; struct node { char str[20]; int sum; Node next; node(){ sum=0; next=NULL; } }; struct mm { Node ss[maxn]; }; struct mm* add(ll m,char s[], struct mm* oo,int t) { Node tmp=(Node)malloc(sizeof(struct node)); strcpy(tmp->str,s); tmp->sum=t; tmp->next=oo->ss[m]; oo->ss[m]=tmp; return oo; } int find(char s[],ll m,struct mm* oo) { int sum=0; if(oo->ss[m]==NULL) return -1; Node ff=oo->ss[m]; while(ff) { if(strcmp(ff->str,s)==0) sum=sum+ff->sum; ff=ff->next; } //对没错就是这部分wa死我了起码wa了10次要吐血了后来才发现!!! if(sum==0) return -1; else return sum; } int main() { char s[20]; int t; int n,m; scanf("%d%d",&n,&m); struct mm* oo=(struct mm*)malloc(sizeof(struct mm)); for(int i=0;i<maxn;i++) { oo->ss[i]=(Node)malloc(sizeof(struct node)); oo->ss[i]=NULL; } for(int i=0;i<n;i++) { scanf("%s %d",s,&t); if(t<m) t=m; long long sum=0; for(int j=0;j<17;j++) sum=sum*10+(s[j]-'0'); if(s[17]=='x')sum=sum+1e18; else sum=sum+s[17]-'0'; sum=sum%maxn; oo=add(sum,s,oo,t); } int gg; scanf("%d",&gg); while(gg--) { scanf("%s",s); long long sum=0; for(int j=0;j<17;j++) sum=sum*10+(s[j]-'0'); if(s[17]=='x')sum=sum+1e18; else sum=sum+s[17]-'0'; sum=sum%maxn; int kk; kk=find(s,sum,oo); if(kk==-1) printf("No Info\n"); else printf("%d\n",kk); } return 0; }