YTU 2975: 我的编号
2975: 我的编号
时间限制: 1 Sec 内存限制: 128 MB
提交: 42 解决: 15
题目描述
建立一个学生链表,每个链表结点含有学生的基本信息,编号和姓名。现在n个学生站成一列,根据学生姓名查找学生的编号。
请将代码补充完整,只需提交补充部分。
请用C++方式提交
C++代码:
#include <iostream>
#include <string.h>
using namespace std;
struct student
{
int number;
char name[20];
student *next;
};
student *createlist(int n)
{
int i;
student *head=NULL;
student *p=NULL;
head=new student;
head->next=NULL;
p=head;
cin>>p->number>>p->name;
for(i=1;i<n;i++)
{
p->next=new student;
p=p->next;
p->next=NULL;
cin>>p->number>>p->name;
}
return head;
}
void searchstu(student *head,char *str)
{
student *current;
current=head;
while(current!=NULL)
{
if(!strcmp(current->name,str))
{
cout<<current->number<<endl;
break;
}
/*
补充部分,当前结点后移
*/
}
}
void destroy(student *head)
{
student *p;
p=head;
while(head!=NULL)
{
p=head;
head=head->next;
delete p;
}
}
int main()
{
int n;
char str[20];
student *head;
cin>>n;
head=createlist(n);
cin>>str;
searchstu(head,str);
destroy(head);
return 0;
}
输入
第1行输入一个n,表示n个学生;
第2行到第n+1行,每行输入一个学生的编号和姓名,以空格隔开;
最后1行,输入要查找的学生姓名。
输出
要寻找学生的编号
样例输入
5
1001 tom
1002 bob
1003 mike
1006 daming
1007 xiaohong
tom
样例输出
1001
你 离 开 了 , 我 的 世 界 里 只 剩 下 雨 。 。 。
#include <iostream>
#include <string.h>
using namespace std;
struct student
{
int number;
char name[20];
student *next;
};
student *createlist(int n)
{
int i;
student *head=NULL;
student *p=NULL;
head=new student;
head->next=NULL;
p=head;
cin>>p->number>>p->name;
for(i=1; i<n; i++)
{
p->next=new student;
p=p->next;
p->next=NULL;
cin>>p->number>>p->name;
}
return head;
}
void searchstu(student *head,char *str)
{
student *current;
current=head;
while(current!=NULL)
{
if(!strcmp(current->name,str))
{
cout<<current->number<<endl;
break;
}
current=current->next;
}
}
void destroy(student *head)
{
student *p;
p=head;
while(head!=NULL)
{
p=head;
head=head->next;
delete p;
}
}
int main()
{
int n;
char str[20];
student *head;
cin>>n;
head=createlist(n);
cin>>str;
searchstu(head,str);
destroy(head);
return 0;
}
#include <string.h>
using namespace std;
struct student
{
int number;
char name[20];
student *next;
};
student *createlist(int n)
{
int i;
student *head=NULL;
student *p=NULL;
head=new student;
head->next=NULL;
p=head;
cin>>p->number>>p->name;
for(i=1; i<n; i++)
{
p->next=new student;
p=p->next;
p->next=NULL;
cin>>p->number>>p->name;
}
return head;
}
void searchstu(student *head,char *str)
{
student *current;
current=head;
while(current!=NULL)
{
if(!strcmp(current->name,str))
{
cout<<current->number<<endl;
break;
}
current=current->next;
}
}
void destroy(student *head)
{
student *p;
p=head;
while(head!=NULL)
{
p=head;
head=head->next;
delete p;
}
}
int main()
{
int n;
char str[20];
student *head;
cin>>n;
head=createlist(n);
cin>>str;
searchstu(head,str);
destroy(head);
return 0;
}
YTU 2975: 我的编号的更多相关文章
- [No0000A8]Word中设置图片下的题注及插入多级列表编号
1.什么是题注? 2.怎么实现一个可以自动更新的题注? 只有先定义好文档编号后,才可以设置出正确的图片下标题注. 文章的结构可以通过导航窗口导航. 导航窗口打开方式. 3.设置好文档编号后,怎样插入 ...
- sql server如何分组编号
我们在生产实践中经常会有这样的需求:分组编号. 如下有一个城市区域表region: 我们需要对上表region按city分组,对region进行排序,得到如下结果: 具体sql如下: select c ...
- MathType6.9按章节插入编号
先插入Chapter,然后修改break主要是该起始编号. 这样话会用一行红色红代码,选中,邮件字体,然后在格式里选择隐藏就好了,这个不能删除.
- latex公式编号
1 \begin{flalign*} 2 % In this way (this arrange of &), the equation will in the center and alig ...
- Loadrunner时间函数、用时间生成订单编号例子
Loadrunner中取时间函数.用时间函数生成订单编号例子: <如要转载,请注明网络来源及作者:Cheers_Lee> 问题的提出: (1)有时候在Loadrunner中用C语言设计脚本 ...
- $\LaTeX$笔记:Section 编号方式(数字、字母、罗马)&计数器计数形式修改
$\LaTeX$系列根目录: Latex学习笔记-序 IEEE模板中Section的编号是罗马数字,要是改投其他刊物的话可能得用阿拉伯数字,所以可以在导言部分做如下修改(放在导言区宏包调用之后): \ ...
- css面包屑导航编号
content:counter(flag);counter-increment: flag;-->一般给导航条编号1,2,3
- ytu 1057: 输入两个整数,求他们相除的余数(带参的宏 + 模板函数 练习)
1057: 输入两个整数,求他们相除的余数 Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 177 Solved: 136[Submit][Status ...
- Latex 建立带有竖线和编号的算法环境
Latex 建立带有竖线和编号的算法环境 Latex源码: \documentclass{article} \usepackage{amssymb} \usepackage{amsmath} \use ...
随机推荐
- Python Tornado简单的http request
这是关于chunk encoding传输以前相关传输编码的处理.没有做压缩解码的处理. import tornado.ioloop import tornado.iostream import soc ...
- [luoguP2831] 愤怒的小鸟(状压DP)
传送门 感觉这题不是很难,但是很恶心. 说一下几点. 1.预处理出来每两个点所构成的抛物线能消除的猪的集合. 2.如果两个点横坐标相同,则不能构成抛物线 3.a >= 0 continue 4. ...
- poj2446 Chessboard 【最大匹配】
题目大意:一个n*m的棋盘,某些格子不能用,问用1*2的骨牌能否完全覆盖这个棋盘,当然,骨牌不能有重叠 思路:显然黑白染色后,一个骨牌只能覆盖一个白色格子和一个黑色格子,然后我们间二染色建图,看能否有 ...
- 51nod1184 第N个质数
如题.$n \leq 1e9$. 方法零:二分,然后洲阁筛.要魔改一下的洲阁筛.跑得慢.卡卡能过.没意思. //#include<iostream> #include<cstring ...
- QueenAttack
问题分析: 1.对于行和列,要求得每行或每列的棋子个数,只需要把横坐标或纵坐标相同的棋子数目相加即可,然后使用k*(k-1)/2就可求得攻击次数 2.对于对角线上的点,需要分析对角线上点的坐标关系.分 ...
- 16 个常用的yum 命令
1. yum [-y] install package_name2. yum remove package_name 卸载指定软件3. ...
- iOS - 系统方法中弃用的关键字的了解 NS_AVAILABLE和NS_DEPRECATED
NS_AVAILABLE_IOS(5_0) 这个方法可以在iOS5.0及以后的版本中使用,如果在比5.0更老的版本中调用这个方法,就会引起崩溃. NS_AVAILABLE(_mac, _ios) ...
- oracle alert 日志位置
Oracle 11g Alert log 文件位置的问题 https://blog.csdn.net/yujin2010good/article/details/7690191 https://blo ...
- python之-- 异常
异常处理: 语法:try: codeexcept (KeyError..可以写多个) as e: error为抓取的多个错误提示,e为错误信息 print(e) # 打印错误信息except (Ind ...
- HDU3430 (置换群循环节+中国剩余定理)
题意:给出n张牌,标号为1-n,然后给出两个序列,序列1表示序列1,2,3,4……,n洗一次牌后到达的,序列2表示目标序列,问初始序列按序列1的洗牌方式洗几次能到达序列2的情况,如果不能到达输出-1. ...