c_cpp 非重复元素的总和

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了c_cpp 非重复元素的总和相关的知识,希望对你有一定的参考价值。

/*
http://ideone.com/hUqkKD
http://www.practice.geeksforgeeks.org/problem-page.php?pid=530
*/

#include <iostream>
using namespace std;

int main() {
	// your code goes here
	int i, n;
	cin >> i;
	while(i--){
		cin >> n;
		int count[1001] = {-1}, x;
		for(int i=0; i<n; i++){
			cin >> x;
			count[x]++;
		}
		int sum =0;
		for(int i=1; i<1001; i++){
			if(count[i] >= 1)
				sum += i;
		}
		cout << sum << endl;
	}
	return 0;
}

以上是关于c_cpp 非重复元素的总和的主要内容,如果未能解决你的问题,请参考以下文章

c_cpp 非连续子序列的最大总和

c_cpp 重复的数字总和

c_cpp 检查数组中是否存在两个元素,其总和等于数组其余部分的总和

c_cpp 最大总和使得没有两个元素相邻

c_cpp 该C程序使用指针计算数组元素的总和。程序使用指针遍历数组并将元素加起来

如何在 PHP 中找到所有 N 个单位数、非重复数字的总和?