CCF-CSP 201803-1 跳一跳
问题描述
代码
# include <bits/stdc++.h>
using namespace std;
int main() {
string line;
getline(cin,line);
stringstream ss(line);
int count = 0;
int temp;
int p = 1;
bool first = true;
while (ss >> temp) {
if (temp == 0) {
break;
}
else if (temp == 1) {
count ++;
p = 1;
}
else {
if (p == 1) {
count += 2;
p = 2;
}
else {
p += 2;
count += p;
}
}
}
cout << count << endl;
return 0;
}