YTU 2952: A代码填充--谁挡住了我

网友投稿 282 2022-08-28

YTU 2952: A代码填充--谁挡住了我

2952: A代码填充--谁挡住了我

时间限制: 1 Sec   内存限制: 128 MB

提交: 135

解决: 38

题目描述

n个人前后站成一列,对于队列中的任意一个人,如果排在他前面的人的身高大于等于他的身高,则称该人被挡住了。小明是队列中的一员,问有多少人挡住了他?

注:本题只需要提交填写部分的代码,请按照C++方式提交。

#include 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<

输入

第一行 n 第二行 n个人的身高 第三行 小明从前往后数的序号

输出

挡住小明的人数

样例输入

10 1.86 1.74 1.67 1.87 1.68 1.9 1.65 1.65 1.68 1.658

样例输出

7

你  离  开  了  ,  我  的  世  界  里  只  剩  下  雨  。  。  。

#include 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<

版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:阿圭罗再见!18年生涯铸传奇,“9320时刻”载史册!(阿圭罗9320)
下一篇:YTU 2955: A改错题--销售部的打印机
相关文章

 发表评论

暂时没有评论,来抢沙发吧~