题解 | 牛牛学数列
牛牛学数列
https://www.nowcoder.com/practice/0b97367cd2184c12a0e02f7c223aee11
#include <iostream>
using namespace std;
int sum(int x)
{
if(x%2==0)
{
return x/2*(-1);
}
else {
return x+sum(x-1);
}
}
int main() {
int a;
while (cin >> a ) { // 注意 while 处理多个 case
cout << sum(a) << endl;
}
}
// 64 位输出请用 printf("%lld")
高中奇偶数列还在追我......