生活随笔
收集整理的这篇文章主要介绍了
PAT 乙级 1041 考试座位号
小编觉得挺不错的,现在分享给大家,帮大家做个参考.
思路是
以“试机座位号”为关键字,“准考证号”和“考试座位号”为值建立一张表,把信息储存到这张表内,查询的时候直接查表即可。
#include <iostream>
#include <string>
#include <map>
#include <algorithm>using namespace std;struct Student
{string id;int pos;
};map<int,Student> m;const Student* find(int pos_temp);int main()
{int n;Student s;int pos_temp;cin>>n;for(int i=0;i<n;i++){cin>>s.id>>pos_temp>>s.pos;m.insert(pair<int,Student>(pos_temp,s));}cin>>n;int* p=new int[n];for(int i=0;i<n;i++)cin>>p[i];const Student* q=NULL;for(int i=0;i<n-1;i++){q=find(p[i]);cout<<q->id<<" "<<q->pos<<endl;}q=find(p[n-1]);cout<<q->id<<" "<<q->pos<<endl;delete p;return 0;
}const Student* find(int pos_temp)
{map<int,Student>::iterator itor=m.find(pos_temp);if(itor!=m.end())return &(itor->second);elsereturn NULL;
}
转载于:https://www.cnblogs.com/FDProcess/p/9236296.html
总结
以上是生活随笔为你收集整理的PAT 乙级 1041 考试座位号的全部内容,希望文章能够帮你解决所遇到的问题。
如果觉得生活随笔网站内容还不错,欢迎将生活随笔推荐给好友。