文章

1

粉丝

8

获赞

1

访问

95

头像
查找学生信息2 题解:正确率只有33%,id不要用int类型改用string过了。我也不知道为什么。
P1476 清华大学机试题
发布于2025年1月25日 17:54
阅读数 95



 
  1. #include
  2. using namespace std;
  3. typedef struct Student{
  4. string id;
  5. string name;
  6. string sex;
  7. string score;
  8. }Student;
  9. int main(){
  10. Student stu;
  11. int n,m;
  12. map mp;
  13. cin >>n;
  14. for(int i = 0; i< n;i++){
  15. cin>>stu.id>>stu.name>>stu.sex>>stu.score;
  16. mp[stu.id]=stu;
  17. }
  18. cin >>m;
  19. for(int i = 0; i< m;i++){
  20. string id;
  21. cin>>id;
  22.  
  23. if(mp.find(id)!=mp.end()){
  24. //printf("%02d",mp[id].id);
  25. cout<
  26. }
  27. else{
  28. cout<<"No Answer!"<
  29. }
  30. }
  31. return 0;
  32. }

 

 

 

 

登录查看完整内容


登录后发布评论

1 条评论
admin SVIP
2025年1月25日 18:02

用int有个问题,学号有前导零和非前导零查找的时候会混淆。

赞(0)