• 1.验证表


    题目

    成绩: 10 / 折扣: 0.8

    应用中有时需要验证来自不同地方的两个表的信息是否一致。本实验编写具有如下功能的程序:输入两个学生记录表LIST1,LIST2,在表LIST2中找出所有没有在表LIST1中出现的学生记录(设表LIST1为基础数据表,非空)。

    每一个学生记录元素包含两个数据项:学号(整数),姓名;

    如果学生记录表LIST2中的记录都包含在LIST1中,则输出the records of LIST2 are all in the LIST1.

    如果学生记录表LIST2中的存在学号,姓名不能与表LIST1完全匹配的记录,则输出 学号(%8d)姓名(%15s)is not in LIST1.

    如果LIST2为空表,则输出the LIST2 is NULL.

     测试输入期待的输出时间限制内存限制额外进程
    测试用例 1以文本方式显示
    1. 5↵
    2. 20120001 zhangli↵
    3. 20120002 wanglei↵
    4. 20120003 duyang↵
    5. 20120004 lixin↵
    6. 20120005 liufan↵
    7. 3↵
    8. 20120001 zhangli↵
    9. 20120006 lixin↵
    10. 20120002 wanglei↵
    以文本方式显示
    1. 20120006 lixin is not in LIST1.↵
    1秒64M0
    测试用例 2以文本方式显示
    1. 5↵
    2. 20120001 zhangli↵
    3. 20120002 wanglei↵
    4. 20120003 duyang↵
    5. 20120004 lixin↵
    6. 20120005 liufan↵
    7. 3↵
    8. 20120001 zhangli↵
    9. 20120004 wanglei↵
    10. 20120006 duyang↵
    以文本方式显示
    1. 20120004 wanglei is not in LIST1.↵
    2. 20120006 duyang is not in LIST1.↵
    1秒64M0
    测试用例 3以文本方式显示
    1. 5↵
    2. 20120001 zhangli↵
    3. 20120002 wanglei↵
    4. 20120003 duyang↵
    5. 20120004 lixin↵
    6. 20120005 liufan↵
    7. 0↵
    以文本方式显示
    1. the LIST2 is NULL.↵
    1秒64M0
    测试用例 5以文本方式显示
    1. 5↵
    2. 20120001 zhangli↵
    3. 20120002 wanglei↵
    4. 20120003 duyang↵
    5. 20120004 lixin↵
    6. 20120005 liufan↵
    7. 3↵
    8. 20120002 wanglei↵
    9. 20120001 zhangli↵
    10. 20120004 lixin↵
    以文本方式显示
    1. the records of LIST2 are all in the LIST1.↵
    1秒64M0


    C++完整代码

    1. #include
    2. #include
    3. #include
    4. using namespace std;
    5. struct Student {
    6. int id;
    7. string name;
    8. };
    9. bool compareStudents(const Student& s1, const Student& s2) {
    10. return s1.id < s2.id;
    11. }
    12. int main() {
    13. vector list1, list2;
    14. //输入表LIST1的学生记录
    15. int n;
    16. cin >> n;
    17. for (int i = 0; i < n; i++) {
    18. Student student;
    19. cin >> student.id;
    20. cin >> student.name;
    21. list1.push_back(student);
    22. }
    23. //输入表LIST2的学生记录
    24. cin >> n;
    25. for (int i = 0; i < n; i++) {
    26. Student student;
    27. cin >> student.id;
    28. cin >> student.name;
    29. list2.push_back(student);
    30. }
    31. if (list2.empty()) {
    32. cout << "the LIST2 is NULL." << endl;
    33. return 0;
    34. }
    35. // 对表LIST1和表LIST2进行排序
    36. sort(list1.begin(), list1.end(), compareStudents);
    37. sort(list2.begin(), list2.end(), compareStudents);
    38. // 循环遍历两个表的学生记录并比较
    39. vector notInList1;
    40. for (const Student& student2 : list2) {
    41. bool found = false;
    42. for (const Student& student1 : list1) {
    43. if (student2.id == student1.id && student2.name == student1.name) {
    44. found = true;
    45. break;
    46. }
    47. }
    48. if (found == false) {
    49. notInList1.push_back(student2);
    50. }
    51. }
    52. // 输出结果
    53. if (notInList1.empty()) {
    54. cout << "the records of LIST2 are all in the LIST1." << endl;
    55. }
    56. else {
    57. for (const Student& student : notInList1) {
    58. cout << student.id << " " << student.name << " is not in LIST1." << endl;
    59. }
    60. }
    61. return 0;
    62. }

  • 相关阅读:
    前端批量下载文件(干货)
    Prometheus基于Consul的 Redis 多实例监控方案
    vue项目中实现用户登录以及token验证
    均匀B样条曲线的表达式
    图书馆公众号自动预约python版
    俄罗斯域名解析遇到的坑~
    javascript回调函数有什么用
    Android基础第十天 | 字节跳动第四届青训营笔记
    Warning: [antd: Switch] `value` is not a valid prop, do you mean `checked`?
    Maven 快速入门
  • 原文地址:https://blog.csdn.net/m0_74200772/article/details/132994976