【洛谷】P1423 小玉在游泳——一个短短for循环解决

版权声明:本文为博主原创文章,未经博主允许不得转载 https://blog.csdn.net/qq_42812128/article/details/86669444

P1423 小玉在游泳

自从上一题看了一位大神的超级精简版for循环之后,我也想用一个超短的for循环,于是就有了下面的代码。

#include<iostream>
using namespace std;
int main(){
	int n;//步数 
	double x,s=0,m=2;//s表示已经游的总路程,m是每次游泳的路程 
	cin>>x;
	for(n=0;s<x;n++,s=s+m,m=m*0.98);
	cout<<n;
	return 0;
}

猜你喜欢

转载自blog.csdn.net/qq_42812128/article/details/86669444