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 ...
随机推荐
- 在WinForm里嵌入WPF模拟公交运行状态
公司有个公交项目,模拟公交运行的时候使用的纯WinForm技术,5秒钟刷新一次,不仅看起来感觉很丑,而且性能上很有问题,听说一段时间后就会因为内存问题崩溃(估计是没释放非托管资源吧,不断重绘,非托管资 ...
- webservice学习第二天
1 课程回顾 l 什么是webservice 远程调用技术:系统和系统之间的调用,获取远程系统里的业务数据 Webservice使用http传输SOAP协议的数据的一种远程调用技术 l Webserv ...
- spring boot学习01【搭建环境、创建第一个spring boot项目】
1.给eclipse安装spring boot插件 Eclipse中安装Spring工具套件(STS): Help -> Eclipse Marketplace... 在Search标签或者Po ...
- [luoguP1352] 没有上司的舞会(DP)
传送门 树上的dp,从底向上dp就行. 设dp[u][0]表示不选节点 u 的最大值,dp[u][1]表示选节点 u 的最大值. 则状态转移方程为: dp[u][0] = ∑max(dp[v][1], ...
- 第k小整数(树状数组)
洛谷传送门 入门难度.. 没错,但是我并不是要暴力做. 而是用树状数组来做. 先离散化,然后随便搞一搞就可以了.(晕.比暴力还慢) 如果要查找某一区间的的话可以把区间取出重新建树,然后再求.(更暴力) ...
- 【分块打表】bzoj 3758 数数
[题目描述] Description 神犇最近闲来无事,于是就思考哲学,研究数字之美.在神犇看来,如果一个数的各位能够被分成两个集合,而且这两个集合里的数的和相等,那么这个数就是优美的(具体原因就只有 ...
- C#.net中当地址有中文时,图片无法显示解决方法
原文发布时间为:2008-11-05 -- 来源于本人的百度文章 [由搬家工具导入] 搞了半天都无法正常显示图片, string path = Server.MapPath("." ...
- 在eclipse中画类图
学习设计模式的时候,希望能够画出类图,理清关系.但是StarUML还有重新去写类名.属性.方法等,不是很方便.网上给出了安装插件的方法额,就可以直接在eclipse中拖拽类,很方便.但是网上给出的插件 ...
- Mysqli的常用函数
Mysqli的常用函数 连接数据库: $res = @mysqli_connect($host,$username,$pass,$db_name); if (mysqli_connect_errno( ...
- HDU 6333 莫队+组合数
Problem B. Harvest of Apples Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 262144/262144 K ...