试题编号: | 201803-1 |
试题名称: | 跳一跳 |
时间限制: | 1.0s |
内存限制: | 256.0MB |
问题描述: | 问题描述 近来,跳一跳这款小游戏风靡全国,受到不少玩家的喜爱。 输入格式 输入包含多个数字,用空格分隔,每个数字都是1,2,0之一,1表示此次跳跃跳到了方块上但是没有跳到中心,2表示此次跳跃跳到了方块上并且跳到了方块中心,0表示此次跳跃没有跳到方块上(此时游戏结束)。 输出格式 输出一个整数,为本局游戏的得分(在本题的规则下)。 样例输入 1 1 2 2 2 1 1 2 2 0 样例输出 22 数据规模和约定 对于所有评测用例,输入的数字不超过30个,保证0正好出现一次且为最后一个数字。 |
#include <map>
#include <cmath>
#include <queue>
#include <cstdio>
#include <string>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <sstream>
#include <time.h>
#include <vector>
#include <list>
using namespace std;
跳一跳
int main()
{
int i,j,num,sum=0,a[30];
int core=1;
a[0] = 5;
for (i = 1; i < 30 && a[i - 1] != 0; i++)
{
scanf_s("%d", &a[i]);
}
for (j = 1; j < i; j++)
{
if (a[j] == 1)
{
sum += 1;
core = 1;
}
else if (a[j] == 2)
{
if (core == 1)
core = 2;
else
core += 2;
sum += core;
}
}
printf("%d\n", sum);
scanf_s("%d", &a[0]);
return 0;
}