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 ...
随机推荐
- 3. express 框架使用 vue框架 weiUI
express 1. 安装 npm install express --save 2. 创建项目 vue js 安装Vuejs vue-cli 是一个官方发布 vue.js 项目脚手架,使用 vue- ...
- 跟初学者学习IbatisNet第三篇
这一章我们主要介绍一下IbatisNet里面的动态sql语句的运用,比如有时候我们想进行模糊查询,参数是动态加入的.或者要实现top n ,order by ,分页等功能的时候,我们就不得不用动态拼接 ...
- 大数据学习——hive的sql练习
1新建一个数据库 create database db3; 2创建一个外部表 --外部表建表语句示例: create external table student_ext(Sno int,Sname ...
- 安装weblogic时,运行configure.cmd报错、闪退、无法创建域
直接运行configure.cmd时在jar包加载完成时,不提示创建域的过程,而是直接退出程序 命令行: cd /d F:\00uep_rfs\wls1212_dev\wls12120 切换至解压路径 ...
- php中configure报错问题
https://blog.csdn.net/dodott/article/details/49664379 PHP的安装虽然有时候很简单,可是如果应用一多,我们安装起来就很头痛了!出错最多的就是安装P ...
- HDU 4334 5-sum
题目大意: 从5个集合中个选取一个数出来,使5个数相加之和为0 , 判断是否存在这种可能 因为集合数目最多200,那么200^3 = 8000000 , 那么这里很明显要把5个数拆成2个和3个计算,因 ...
- 洛谷P1145 约瑟夫
题目描述 n个人站成一圈,从某个人开始数数,每次数到m的人就被杀掉,然后下一个人重新开始数,直到最后只剩一个人.现在有一圈人,k个好人站在一起,k个坏人站在一起.从第一个好人开始数数.你要确定一个最小 ...
- jvm的类加载器,类装载过程
混沌初开,在一片名为jvm的世界中,到处都是一片虚无,直到一个名为BootstrapClassLoader的巨人劈开了世界,据说它是由名叫C++的女神所造,它从一个叫做jre/lib的宝袋中拿出一把开 ...
- BZOJ1573: [Usaco2009 Open]牛绣花cowemb
求半径d<=50000的圆(不含边界)内n<=50000条直线有多少交点,给直线的解析式. 一开始就想,如果能求出直线交点与原点距离<d的条件,那么从中不重复地筛选即可.然而两个kx ...
- Codeforces Round #533 (Div. 2) E 最大独立集
知识点 最大独立集(set) = 补图的最大团(clique ) 最小顶点覆盖 + 最大独立集 = V E. Helping Hiasat time limit per test 2 seconds ...