具体代码如下:
#include <iostream>
#include <stdio.h>
using namespace std;
int main()
{
int cur = 1, sum = 0, two = 0; //依次表示当前扫描数字,总得分,连续2出现的次数
while(~scanf_s("%d", &cur) && cur)
{
if(cur == 1) { sum += 1; two = 0; }
else if(cur == 2) { two++; sum += 2 * two; }
}
cout << sum << endl;
return 0;
}