kikit
6/23/2016 - 1:05 PM

Sum of non-repeated elements

Sum of non-repeated elements

/*
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;
}