HD-ACM算法專攻系列(14)——find your present (2)
阿新 • • 發佈:2017-10-07
sent logs light com cnblogs space 問題 bool std
問題描述:
源碼:
#include"iostream" #include"algorithm" using namespace std; bool cmp(int a, int b) { return a < b; } int main() { int n, result; int *p; while(true) { scanf("%d", &n); if(n == 0)break; p = new int[n]; for(int i = 0; i < n; i++) { scanf("%d", p+i); } sort(p, p+n, cmp); result = p[0]; if(n > 1) { // if(p[0] != p[1]) // { // result = p[0]; // } for(int i = 1; i < n - 1; i++) { if(p[i - 1] != p[i] && p[i] != p[i+1]) { result = p[i]; break; } } if(p[n - 2] != p[n - 1]) { result = p[n - 1]; } } cout<<result<<endl; } return 0; }
HD-ACM算法專攻系列(14)——find your present (2)