上链接~ URL
题目:陶陶家的院子里有一棵苹果树,每到秋天树上就会结出 1010 个苹果。苹果成熟的时候,陶陶就会跑去摘苹果。陶陶有个 3030 厘米高的板凳,当她不能直接用手摘到苹果的时候,就会踩到板凳上再试试。
现在已知 10 个苹果到地面的高度,以及陶陶把手伸直的时候能够达到的最大高度,请帮陶陶算一下她能够摘到的苹果的数目。假设她碰到苹果,苹果就会掉下来。
上代码:
#include <bits/stdc++.h> //start coding!
using namespace std;
int main () //main function
{
int apples=0,height,a[10],stool=30; //read data
//input
//the list(a) 10 items,from 0 to 9
for(int i=0;i<=9;i++) //cin 10 apples height
{
cin>>a[i];
}
cin>>height; //cin TaoTao's height
height=height+stool; //TaoTao and the stool's height
//list every possible situation
for(int j=0;j<=9;j++)
{
if(height<a[j]) apples=apples; else apples++;
}
cout<<apples; //output the answer
return 0; //end
}
两个循环,搞定问题
注:代码为原创,仅供学习研究使用,否则禁止转载