首页 > 试题广场 >

查找学生信息

[编程题]查找学生信息
  • 热度指数:37199 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 64M,其他语言128M
  • 算法知识视频讲解
输入N个学生的信息,然后进行查询。

输入描述:
输入的第一行为N,即学生的个数(N<=1000)
接下来的N行包括N个学生的信息,信息格式如下:
01 李江 男 21
02 刘唐 男 23
03 张军 男 19
04 王娜 女 19
然后输入一个M(M<=10000),接下来会有M行,代表M次查询,每行输入一个学号,格式如下:
02
03
01
04


输出描述:
输出M行,每行包括一个对应于查询的学生的信息。
如果没有对应的学生信息,则输出“No Answer!”
示例1

输入

4
01 李江 男 21
02 刘唐 男 23
03 张军 男 19
04 王娜 女 19
5
02
03
01
04
03

输出

02 刘唐 男 23
03 张军 男 19
01 李江 男 21
04 王娜 女 19
03 张军 男 19
头像 PeapEapeA
发表于 2021-02-28 01:23:04
c。这个题的测试用例和示例太坑了吧,测试用例没有前缀0,示例却有。。。 #include<stdio.h> typedef struct _stu{ int no; char name[20]; char sex[10]; int age; }stu; 展开全文
头像 philos
发表于 2021-02-05 21:38:44
思路 哈希表存学生学号和信息的对应就 ok 了 #include<iostream> #include<unordered_map> using namespace std; int main(){ int n, m; while(cin >> 展开全文
头像 普罗列塔丽亚
发表于 2022-01-14 17:49:50
字段组成一个长string模拟输出即可,不需要结构体 string不要用scanf强行&str[0],无法接受size()会导致拼接时错误,要用cin输入 #include<stdio.h> #include<iostream> #include&l 展开全文
头像 CooKing
发表于 2023-03-12 09:44:06
#include <iostream> #include <string> #include <map> using namespace std; struct Stu{ char id[5]; char name[10]; char s 展开全文
头像 易水寒learning
发表于 2022-01-24 20:58:28
#include<iostream> #include<cstdio> #include<map> using namespace std; map<string, string> student; //map 展开全文
头像 位琬续
发表于 2021-03-11 14:14:31
1、定义学生类:学号,姓名,性别,年龄2、重写输入输出函数(io)3、根据建立学号和学生的对应关系4、根据学号找学生,可以使用find和count,不要使用中括号查找; #include <iostream> #include <map> using namespace st 展开全文
头像 一枚小趴菜o00o
发表于 2024-03-24 14:42:05
可以直接看成两个字符串,然后利用map的at()返回值与count()看是否存在。 #include <iostream> #include <string> #include <map> using namespace std; map<string,st 展开全文
头像 宁静的冬日
发表于 2022-03-06 11:36:25
C++ ">#include<string> using namespace std; #define MAX 1000 class Student { public: string id;//学号 string name; string sex;//true男,false女 i 展开全文
头像 苇岸弦歌
发表于 2023-03-02 12:35:52
#include <iostream> #include "unordered_map" using namespace std; struct student { string name; string sex; int age; }; in 展开全文
头像 小黑狼1号
发表于 2024-02-02 10:37:02
#include <cstdio> #include <iostream> #include <string> #include <algorithm> using namespace std; struct student{ string 展开全文