当前位置:网站首页>CCF 201803_1 跳一跳
CCF 201803_1 跳一跳
2022-07-22 09:53:00 【你这个代码我看不懂】
CCF 201803_1
问题描述
近来,跳一跳这款小游戏风靡全国,受到不少玩家的喜爱。
简化后的跳一跳规则如下:玩家每次从当前方块跳到下一个方块,如果没有跳到下一个方块上则游戏结束。
如果跳到了方块上,但没有跳到方块的中心则获得1分;跳到方块中心时,若上一次的得分为1分或这是本局游戏的第一次跳跃则此次得分为2分,否则此次得分比上一次得分多两分(即连续跳到方块中心时,总得分将+2,+4,+6,+8...)。
现在给出一个人跳一跳的全过程,请你求出他本局游戏的得分(按照题目描述的规则)。
输入格式
输入包含多个数字,用空格分隔,每个数字都是1,2,0之一,1表示此次跳跃跳到了方块上但是没有跳到中心,2表示此次跳跃跳到了方块上并且跳到了方块中心,0表示此次跳跃没有跳到方块上(此时游戏结束)。
输出格式
输出一个整数,为本局游戏的得分(在本题的规则下)。
样例输入
1 1 2 2 2 1 1 2 2 0
样例输出
22
数据规模和约定
对于所有评测用例,输入的数字不超过30个,保证0正好出现一次且为最后一个数字。
代码提交:
#include <iostream>
#include <vector>
using namespace std;
int main() {
int num;
cin>>num;
int score=0;
vector<int> jump;
int continuous1=0; // 初始化为0
int continuous2=0; // 初始化为0
while(num!=0){
jump.push_back(num);
cin>>num;
}
/*for(int i=0;i<jump.size();++i){
cout<<jump[i]<<" ";
}*/
for(vector<int>::iterator iter=jump.begin();iter!=jump.end();++iter){
if(iter==jump.begin() && *iter==2){
continuous2++;
score+=2;
}
else if(iter==jump.begin() && *iter==1){
continuous1=1;
score+=1;
}
else if(*iter==1){
continuous1=1;
continuous2=0;
score+=1;
}
else if(*iter==2){
continuous2++;
continuous1=0;
if(continuous1){
score+=2;
}
else{
score+=continuous2*2;
}
}
}
cout<<score;
return 0;
}
边栏推荐
- Grafana panel - modify visual text and background colors
- Grafana panel - about conversion
- SQL Design Teaching Management Library
- 用指针遍历数组
- 【commons-beanutils专题】005- ConvertUtils 专题
- Jackson parsing JSON detailed tutorial
- 【带你学c带你飞】浙大版《C语言程序设计(第3版)》第3章 分支结构(习题3)
- pytest接口自动化测试框架 | unittest与pytest的区别
- 4G工业路由器大气环境监测方案
- No longer clinging to products, apple cook increased the investment in American antitrust Lobbying: it spent $4.6 million in the first half of this year
猜你喜欢
Scope and lifecycle of beans
有向图的连通性
不再执着于用产品说话,苹果库克加大美国反垄断游说投入:今年上半年支出 460 万美元
NLP text classification top meeting paper reading notes for natural language processing (2)
experience""/>
Renjie, chief scientist of rongyun: experience produces talents, and career "experience > experience"
错过等一年!百度超级链数藏发行服务限时五折
Nacos persistent connection MySQL database SM4 encryption scheme
【带你学c带你飞】第3章 分支结构(练习3.1 简单的猜数游戏)
Swagger UI introduction and common notes
关于人力外包公司那些事
随机推荐
About human resource outsourcing companies
各种 XSS Payload 速查清单
The problem that double type cannot be accurately calculated
4G工业路由器大气环境监测方案
MySQL implements querying data from other tables and inserting another table
pytest接口自动化测试框架 | 为什么要做pytest插件的二次开发
Leetcode daily question 2022/3/7-2022/3/13
Grafana panel - override field values
JS advanced - understanding of objects
Leetcode daily question 2022/2/7-2022/2/13
蓝队资源大合集
7.19 二叉树
工业路由器油田无线监控
关于人力外包公司那些事
In his early 30s, he became a doctoral director of Fudan University. Chen Siming: I want to write both codes and poems
Encryption and decryption of 535 tinyurl
万兴PDF专家v8.3.8.1253专业版
The force deduction method summarizes the k-diff number pairs in the 532 array
Terminal data protection of Internet communication security
An analysis of the CPU surge of an RFID tag management system in.Net