本题比较简单,注意每次输入新的一组数据时将变量清零。
#include <iostream>
using namespace std;
int main()
{
int n, now;
while (cin >> n)
{
if (n == 0)
break;
int pre = 0, total = 0;
for (int i = 0; i < n; i++)
{
cin >> now;
if (now > pre)
{
total += (now - pre) * 6;
pre = now;
}
else
{
total += (pre - now) * 4;
pre = now;
}
}
total += n * 5;
cout << total << endl;
}
return 0;
}
继续加油。