YTU 2952: A代码填充--谁挡住了我
2952: A代码填充--谁挡住了我
时间限制: 1 Sec 内存限制: 128 MB
提交: 135 解决: 38
题目描述
n个人前后站成一列,对于队列中的任意一个人,如果排在他前面的人的身高大于等于他的身高,则称该人被挡住了。小明是队列中的一员,问有多少人挡住了他?
注:本题只需要提交填写部分的代码,请按照C++方式提交。
#include <iostream>
using namespace std;
struct Node
{
float height;
Node *next;
};
Node *creatlist(int n)
{
Node *t=new Node;
cin>>t->height;
if(n>1)
t->next = creatlist(n-1);
else
t->next = NULL;
return t;
}
Node *findlist(Node *head,int n)
{
if(n<1||!head)
return NULL;
if(n==1)
return head;
return findlist(head->next,n-1);
}
int countlist(Node *head,Node *p)
{
if(!head||!p||head==p)
return 0;
/*
请在该部分补充缺少的代码
*/
}
int main(void)
{
int n,pos;
Node *head,*xiaoming;
cin>>n; //人数
head = creatlist(n);
cin>>pos; //小明的序号
xiaoming = findlist(head,pos);
cout<<countlist(head,xiaoming)<<endl;
return 0;
}
输入
第一行 n
第二行 n个人的身高
第三行 小明从前往后数的序号
输出
挡住小明的人数
样例输入
10
1.86 1.74 1.67 1.87 1.68 1.9 1.65 1.65 1.68 1.65
8
样例输出
7
你 离 开 了 , 我 的 世 界 里 只 剩 下 雨 。 。 。
#include <iostream>
using namespace std;
struct Node
{
float height;
Node *next;
};
Node *creatlist(int n)
{
Node *t=new Node;
cin>>t->height;
if(n>1)
t->next = creatlist(n-1);
else
t->next = NULL;
return t;
}
Node *findlist(Node *head,int n)
{
if(n<1||!head)
return NULL;
if(n==1)
return head;
return findlist(head->next,n-1);
}
int countlist(Node *head,Node *p)
{
if(!head||!p||head==p)
return 0;
int i=0;
while(head!=p)
{
if(head->height>=p->height)
{
i++;
}
head=head->next;
}
return i;
}
int main(void)
{
int n,pos;
Node *head,*xiaoming;
cin>>n; //人数
head = creatlist(n);
cin>>pos; //小明的序号
xiaoming = findlist(head,pos);
cout<<countlist(head,xiaoming)<<endl;
return 0;
}
#include <iostream>
using namespace std;
struct Node
{
float height;
Node *next;
};
Node *creatlist(int n)
{
Node *t=new Node;
cin>>t->height;
if(n>1)
t->next = creatlist(n-1);
else
t->next = NULL;
return t;
}
Node *findlist(Node *head,int n)
{
if(n<1||!head)
return NULL;
if(n==1)
return head;
return findlist(head->next,n-1);
}
int countlist(Node *head,Node *p)
{
if(!head||!p||head==p)
return 0;
int i=0;
while(head!=p)
{
if(head->height>=p->height)
{
i++;
}
head=head->next;
}
return i;
}
int main(void)
{
int n,pos;
Node *head,*xiaoming;
cin>>n; //人数
head = creatlist(n);
cin>>pos; //小明的序号
xiaoming = findlist(head,pos);
cout<<countlist(head,xiaoming)<<endl;
return 0;
}
YTU 2952: A代码填充--谁挡住了我的更多相关文章
- YTU 2953: A代码填充--学画画
2953: A代码填充--学画画 时间限制: 1 Sec 内存限制: 128 MB 提交: 62 解决: 52 题目描述 最近小平迷上了画画,经过琨姐的指导,他学会了RGB色彩的混合方法.对于两种 ...
- YTU 2959: 代码填充--雨昕学矩阵
2959: 代码填充--雨昕学矩阵 时间限制: 1 Sec 内存限制: 128 MB 提交: 112 解决: 50 题目描述 雨昕开始学矩阵了.矩阵数乘规则:一个数k乘一个矩阵A还是一个矩阵,行数 ...
- YTU 2958: 代码填充--雨昕学画画
2958: 代码填充--雨昕学画画 时间限制: 1 Sec 内存限制: 128 MB 提交: 156 解决: 102 题目描述 雨昕开始学画水彩画,老师给雨昕一个形状(Shape)类,雨昕在Sha ...
- 如何用代码填充S/4HANA销售订单行项目的数量字段
我的任务是用代码生成S/4HANA销售订单(Sales Order)的行项目,并且填充对应的quantity(数量)值. 最开始我用了下面的代码,把quantity的值写入item字段target_q ...
- YTU 2616: A代码完善--简易二元运算
2616: A代码完善--简易二元运算 时间限制: 1 Sec 内存限制: 128 MB 提交: 280 解决: 187 题目描述 注:本题只需要提交填写部分的代码,请按照C++方式提交. 编写二 ...
- YTU 2614: A代码完善--系统日期
2614: A代码完善--系统日期 时间限制: 1 Sec 内存限制: 128 MB 提交: 216 解决: 113 题目描述 注:本题只需要提交填写部分的代码,请按照C++方式提交. 已知某操作 ...
- YTU 2611: A代码完善--向量的运算
2611: A代码完善--向量的运算 时间限制: 1 Sec 内存限制: 128 MB 提交: 256 解决: 168 题目描述 注:本题只需要提交填写部分的代码,请按照C++方式提交. 对于二维 ...
- YTU 2607: A代码填空题--更换火车头
2607: A代码填空题--更换火车头 时间限制: 1 Sec 内存限制: 128 MB 提交: 91 解决: 73 题目描述 注:本题只需要提交填写部分的代码,请按照C++方式提交. 假设火车有 ...
- 使用Xcode HeaderDoc和Doxygen文档化你的Objective-C和Swift代码
在一个应用的整个开发过程中涉及到了无数的步骤.其中一些是应用的说明,图片的创作,应用的实现,和实现过后的测试阶段.写代码可能组成了这个过程的绝大部分,因为正是它给了应用生命,但是这样还不够,与它同等重 ...
随机推荐
- 发布tomcate时报A configuration error occurred during startup.please verify the preference field with the prompat:null
发布tomcate时报A configuration error occurred during startup.please verify the preference field with the ...
- 实现List集合中数据逆序排列
Collections.reverse(list); 实现list集合逆序排列
- zoj 1109 Language of FatMouse(map)
Language of FatMouse Time Limit: 10 Seconds Memory Limit: 32768 KB We all know that FatMouse do ...
- 【计算几何】FZU Problem 2270 Two Triangles
http://acm.fzu.edu.cn/problem.php?pid=2270 [题意] 给定6到10个点,从中选出6个不同的点组成两个三角形,使其中一个三角形可以通过另一个三角形平移和旋转得到 ...
- 转 asterisk拨号规则
asterisk拨号规则 一.前言 本文档以asterisk-1.4.32为基础写作而成,可能和其他版本有些区别. 二.Asterisk dialplan 基本结构 Asterisk dial ...
- eclipse提速02 - eclipse.ini优化
给eclipse执行jvm.它可以让你使用自己的jdk,而不是系统环境变量所指定的jdk -vm /path/to/your/java 使用最新的jdk来运行eclipse.使用最新的jdk要好很多. ...
- Org-mode五分钟教程ZZZ
Table of Contents 1 源起 2 简介 2.1 获取 org-mode 2.2 安装 3 基础用法 3.1 创建一个新文件 3.2 简单的任务列表 3.3 使用标题组织一篇文章 3.4 ...
- 前端3D、动画相关开源JS
WebGL http://taobaofed.org/blog/2015/12/21/webgl-handbook/ D3 (或者叫 D3.js )是一个基于 web 标准的 JavaScript 可 ...
- 2016.3.15__H5页面实战__第七天
假设您认为这篇文章还不错,能够去H5专题介绍中查看很多其它相关文章. 个人简书地址: dhttp://www.jianshu.com/users/5a2fd0b8fb30/latest_article ...
- eclipse中maven插件上传项目jar包到私服
我们知道,每一个公司都会有自己的工具包或公共包.这样的包就能够上传到公司的maven私服,就不用每一个人都去同步开发包了. 那么,怎么把本地项目打包并公布到私服呢?依照例如以下步骤就能够轻松完毕. 1 ...