题目描述
简单模拟
C++ 代码
#include <iostream>
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define INF 0x3f3f3f3f
#define inf 0x3f3f3f3f3f3f3f3f
#define rep(i,a,b) for(auto i=a;i<=b;++i)
#define bep(i,a,b) for(auto i=a;i>=b;--i)
#define lowbit(x) x&(-x)
#define PII pair<int,int>
#define PLL pair<ll,ll>
#define PI acos(-1)
#define pb push_back
#define eps 1e-6
const int mod = 1e9 + 7;
const int MOD = 1e4+7;
const int N = 1e6 + 10;
const int M = 1111;
int dx[]={-1, 0, 1, 0};
int dy[]={0, 1, 0, -1};
int dxy[][2]={{0,1},{1,0},{1,1},{-1,1}};
using namespace std;
void solve(){
int tot=0;
int pos=1;
int k;
while(cin>>k){
if(!k) break;
else if(k==1){
pos=1;
tot++;
}
else if(k==2){
if(pos==1) pos=2;
else pos+=2;
tot+=pos;
}
}
cout<<tot<<endl;
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
solve();
return 0;
}
你前面写这么多对这道题没用的东西干嘛?