求助
查看原帖
求助
258178
Benzenesir楼主2021/11/14 20:45

只有40分,思路就是加上第一个数和其他数的绝对值,subtask1和4过了,其余全红,求dalao纠错

代码:

#include <cstdio>
#include <cstring>
#include <string>
#include <algorithm>

using namespace std;


int main(){
	int n;
	cin >> n;
	int temp,ans=0;
	cin >> temp;
	ans+=temp; 
	for(int i=2;i<=n;i++){
		cin >> temp;
		if(temp<0)ans-=temp;
		else ans+=temp;
	}
	
	cout << ans << endl;
	
	return 0;
}

2021/11/14 20:45
加载中...