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代码
在一个应用的整个开发过程中涉及到了无数的步骤.其中一些是应用的说明,图片的创作,应用的实现,和实现过后的测试阶段.写代码可能组成了这个过程的绝大部分,因为正是它给了应用生命,但是这样还不够,与它同等重 ...
随机推荐
- Mac 10.10 配置apache
配置php 命令行工具:http://blog.csdn.net/evane1890/article/details/38759073 自从系统从OS X Mavericks 10.9升级到OS X ...
- POJ-Crazy tea party,很好的一道数学题~~~
Crazy tea party Time Limit: 1000MS Memory Limit: 10000K Description n participants of <& ...
- Archiving not possible: No primary destinations errors
If space ran out in an archive destination, after you fix the problem, you may still recieve the fol ...
- 以太坊和IPFS如何存储数据
如何将JSON文件存储在IPFS上,并使用Oraclize访问智能合约中的数据呢? 以太坊是一个成熟的区块链,使开发人员能够创建智能合约,在区块链上执行的程序可以由交易触发.人们经常将区块链称为数据库 ...
- [luoguP1772] [ZJOI2006]物流运输(DP + spfa)
传送门 预处理cost[i][j]表示从第i天到第j天起点到终点的最短距离 f[i]表示前i天到从起点到终点的最短距离 f[0] = -K f[i] = min(f[i], f[j - 1] + co ...
- 同步OR异步?WebFlux开发真的比Servlet开发要快?顺便再科普下CompletableFuture
在看下文之前,先给大家科普一点基础知识 Runable:线程任务类接口,没有返回值 Callable:与上面的不同就是有返回值 Executor:定义了线程池执行任务的接口,不过只定义了Runable ...
- hdu 2438 Turn the corner [ 三分 ]
传送门 Turn the corner Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Othe ...
- CSY版最大团,速度快一倍
#include <bits/stdc++.h> using namespace std; #define REP(i, n) for(int i(0); i < (n); ++i) ...
- SpringMvc架构流程
- asp.net core 集成JWT(二)token的强制失效,基于策略模式细化api权限
[前言] 上一篇我们介绍了什么是JWT,以及如何在asp.net core api项目中集成JWT权限认证.传送门:https://www.cnblogs.com/7tiny/p/11012035.h ...