#include <iostream>
爬虫问题 ,虫子每次爬u米,休息一分钟下落d米,井深n米 ,爬总高度为h
using namespace std;
int _time (int n,int u,int d);
int main() {
int n1,u1,d1; //输入输出
int n2,u2,d2;
int n3,u3,d3;
cin>>n1>>u1>>d1;
cin>>n2>>u2>>d2;
cin>>n3>>u3>>d3;
if(n1!=0) {
cout<<_time(n1,u1,d1)<<endl;
}
if(n2!=0) {
cout<<_time(n2,u2,d2)<<endl;
}
if(n3!=0) {
cout<<_time(n3,u3,d3)<<endl;
}
return 0;
}
int _time (int n,int u,int d) {
int h =0;
int time=0;
int win =0;
while(win!=1) { //win用来控制循环
h=h+u; //向上爬
time++;
if(h>=n) { //判断是否爬到井口
win=1;
} else {
h=h-d; //向下滑
time++;
}
}
return time;
}
爬虫就是要来用代码模拟虫子向上向下爬的过程,就是两个变量的加减法,就是多了一个哨兵变量来判断是否爬到井口
要多把文字翻译成代码就会了,再多会一些算法,多见一些代码,多做码农