当前位置:网站首页>洛谷陶陶摘苹果
洛谷陶陶摘苹果
2022-07-27 05:04:00 【竹林居士-】
题目描述
陶陶家的院子里有一棵苹果树,每到秋天树上就会结出 10个苹果。苹果成熟的时候,陶陶就会跑去摘苹果。陶陶有个 30 厘米高的板凳,当她不能直接用手摘到苹果的时候,就会踩到板凳上再试试。
现在已知 101个苹果到地面的高度,以及陶陶把手伸直的时候能够达到的最大高度,请帮陶陶算一下她能够摘到的苹果的数目。假设她碰到苹果,苹果就会掉下来。
输入格式
输入包括两行数据。第一行包含 10 个 100 到 200之间(包括 100 和 200 )的整数(以厘米为单位)分别表示 10个苹果到地面的高度,两个相邻的整数之间用一个空格隔开。第二行只包括一个 100到 120之间(包含 100和 120)的整数(以厘米为单位),表示陶陶把手伸直的时候能够达到的最大高度。
输出格式
输出包括一行,这一行只包含一个整数,表示陶陶能够摘到的苹果的数目。
输入输出
输入
100 200 150 140 129 134 167 198 200 111 110
输出
5
审题:轮流输入10个苹果高度,然后与陶陶身高+30比较,如果小于,就res+1。
步骤:
1.定义变量
int a[15],n,ans=0;
2.输入苹果高度
for(int i=1;i<=10;i++)
{
cin>>a[i];
} 3.输入身高、比较
cin>>n;
for(int i=1;i<=10;i++)
{
if(n+30>=a[i])
ans++;
}输出:
cout<<ans<<endl;完整代码:
#include<iostream>
using namespace std;
int a[15],n,ans=0;
int main()
{
for(int i=1;i<=10;i++)
{
cin>>a[i];
}
cin>>n;
for(int i=1;i<=10;i++)
{
if(n>=a[i] || (n+30)>=a[i])
ans++;
}
cout<<ans<<endl;
return 0;
}新手,请多指教
边栏推荐
- Common commands in CONDA and pip environments
- 我的第一篇博客
- Trying to evolve_ My first CSDN blog
- C language makes a small maze
- 初识C语言——常量、变量
- p7 day1 初识Flask框架
- Multiplication sorting in torch, * & torch. Mul () & torch. MV () & torch. Mm () & torch. Dot () & @ & torch. Mutmal ()
- 编辑删除用户
- Program environment and preprocessing (Part 1): how does a program run successfully?
- Makefile 通俗易懂详解
猜你喜欢

Share a multiple-choice question about variables (including global variables, local variables, the scope of variables, and life cycle knowledge points)

努力进化中_我的第一篇csdn博客

下载url-loader,用limit指定图片大小后,显示不出图片

使用vertical-align不能让图片和文字垂直居中对齐

Day5 --- Flask-RESTful请求响应与SQLAlchemy基础

Trying to evolve_ My first CSDN blog

函数和箭头函数

Li Hongyi machine learning team learning punch in activity day05 --- skills of network design

Pytorch installation new pit

Carmaker quick start lesson 4 developing 48V P1 hybrid system
随机推荐
Redis transaction
用户-注册-登录
JS中深拷贝和浅拷贝的区别
Flask框架创建项目初期总结
Li Hongyi machine learning team learning punch in activity day04 - Introduction to deep learning and back propagation mechanism
First acquaintance with C language - first acquaintance with pointer
C语言字符串介绍以及相关操作函数
js中isNaN和Number.isNaN的区别
C语言进制转换以及原补反码位运算介绍
Introduction to C language
User management - paging
Makefile is easy to understand and explain
Looking at the PK of alphago and Li Shishi from a deep perspective
退出登录与jsx显示
小米商城项目_注册
Introduction of C language base conversion and original complement inverse code point operation
图片上传的逻辑
C language string introduction and related operation functions
p7 day1 初识Flask框架
Day6 --- SQLAlchemy进阶