fork download
  1. #include <iostream>
  2. #include <vector>
  3. #include <cstdint>
  4. #include <algorithm>
  5.  
  6. typedef std::vector<std::int64_t> DType;
  7.  
  8. DType::value_type MakeHoge(DType D) {
  9.  
  10. std::sort(D.begin(), D.end());
  11. std::size_t i = 0;
  12. for (i = 1; i < D.size() - 1; i++) {
  13. if (D[i - 1] != D[i]) {
  14. if (D[i] == D[i + 1])continue;
  15.  
  16. return D[i];
  17. }
  18. }
  19. if (D[i] != D[i - 1])return D[i];
  20. return -1;
  21. }
  22.  
  23. int main() {
  24. DType D = { 1,1,1,1,2,2,2,3,3,4 };
  25. std::cout << MakeHoge(D) << std::endl;
  26. D = DType{ 1,2,3,4,5,5,4,3,2,1 };
  27. std::cout << MakeHoge(D) << std::endl;
  28. D = DType{ 3,1,4,1,5,9,2,6,5,3,5 };
  29. std::cout << MakeHoge(D) << std::endl;
  30. return 0;
  31. }
Success #stdin #stdout 0s 4520KB
stdin
Standard input is empty
stdout
4
-1
2