wechat jump

The main idea of ​​the title is as follows: WeChat jumps the game, input three numbers 1, 2, and 0;

1 means jumping to the next box but not in the center, the score is 1, and the total score is increased by 1;

2 means jumped to the next box and is in the center; calculated according to the previous score: if the previous score was 1, then this time the score is 2, and the total score is added 2 points, if the previous score was 2, then this time the score is 4, add 4 to the total score; and so on: if the last time the score was 8, and this time jumped to the center of the box, then the score this time is 10, and the total score is added by 10;

0 means not jumping on the box and the game is over.

-------------------------------------------------------------------------------------------------------

Input requirements: a set of integers (1, 2, 0), separated by spaces, guaranteed to end with 0, and a set of data with one and only one 0.

Input: 1 1 2 2 1 1 2 2 2 0

output: 22

The output description is: 1+1+2+4+1+1+2+4+6= 22

=====================================

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

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324651318&siteId=291194637