int a[] = {2,3,4,5,10}; int n = 5; vector<int> coll(a,a+n); sort(coll.begin(), coll.end(), greater<int>()); //copy(coll.begin(), coll.end(), ostream_iterator<int>(cout, " ")); bool found = false; for (int i = 0; i < n - 2; ++i) { cout<<coll[i]<<endl; if (coll[i] < coll[i + 1] + coll[i + 2]) { cout << coll[i] + coll[i + 1] + coll[i + 2] << endl; found = true; break; } } if (!found) { cout << 0 << endl; }
时间: 2024-10-11 07:22:45