首页 > 代码库 > Bestcoder Round8

Bestcoder Round8

4989Summary

既然用C++了就偷懒直接用STL大法了

#include<iostream>#include<algorithm>#include<vector>using namespace std;int main(){    int n;    while (cin >> n)    {        vector<long long> vec,temp;        long long a;        //读取数据        while (n--){            cin >> a;            temp.push_back(a);        }        //计算加法,压入vec中            int i, j;        for (i = 0; i < (int)temp.size() - 1;i++)        for (j = i + 1; j < (int)temp.size(); j++)            vec.push_back(temp[i] + temp[j]);        //排序,去重        sort(vec.begin(), vec.end());        vector<long long>::iterator ite_end;        ite_end = unique(vec.begin(), vec.end());        vec.erase(ite_end, vec.end());        //遍历求和        long long sum=0;        vector<long long>::iterator ite;        for (ite = vec.begin(); ite != vec.end(); ite++)            sum += *ite;        cout << sum << endl;    }    return 0;}

 

Bestcoder Round8