Run ID | 作者 | 问题 | 语言 | 测评结果 | Time | Memory | 代码长度 | 提交时间 |
---|---|---|---|---|---|---|---|---|
1726 | 邓小龙 | 13求1+2-3+4-5+……n的值 | C++ | Accepted | 0 MS | 264 KB | 335 | 2023-11-04 18:03:58 |
# include<iostream> # include<cmath> //# include<bits/stdc++.h>//万能头文件 using namespace std; int main(){ int s=0,n; cin>>n; for(int i=1;i<=n;i++){ if(i==1) s+=i; else if(i%2==0) s+=i; else s-=i; } cout<<s<<endl; return 0; }