CSP考试 2018年3月第1题 跳一跳 C++实现

#include <iostream>
using namespace std;
int main()
{
	int jg=0;
	int f=0;
	while(1)
	{
		int a;
		cin>>a;
		if(a==0)
		{
			break;
		}
		if(a==2)
		{
			f++;
		}else
		{
			f=0;
		}
		if(f>=1)
		{
			jg=jg+f*2;
		}else
		{
			jg=jg+a;
		}
	}
	cout<<jg<<endl;
	return 0;
} 


猜你喜欢

转载自blog.csdn.net/woniupengpeng/article/details/79923148
今日推荐