fork download
  1. #include <iostream>
  2. #include <vector>
  3. #include <cstdint>
  4. #include <algorithm>
  5. #include <map>
  6.  
  7. typedef std::vector<std::int64_t> DType;
  8.  
  9. typedef std::map<std::uint64_t, std::uint64_t> MType;
  10.  
  11. std::int64_t MakeHoge2(const DType& D) {
  12. MType M;
  13.  
  14. for (auto& o : D) {
  15. M[o]++;
  16. }
  17. for (auto& o : M) {
  18. if (o.second == 1) {
  19. return o.first;
  20. }
  21. }
  22. return -1;
  23.  
  24. }
  25.  
  26.  
  27. /** /
  28. DType::value_type MakeHoge(DType D) {
  29.  
  30. std::sort(D.begin(), D.end());
  31. std::size_t i = 0;
  32. for (i = 1; i < D.size() - 1; i++) {
  33. if (D[i - 1] != D[i]) {
  34. if (D[i] == D[i + 1])continue;
  35.  
  36. return D[i];
  37. }
  38. }
  39. if (D[i] != D[i - 1])return D[i];
  40. return -1;
  41. }
  42. /**/
  43. int main() {
  44. DType D = { 1,1,1,1,2,2,2,3,3,4 };
  45. std::cout << MakeHoge2(D) << std::endl;
  46. D = DType{ 1,2,3,4,5,5,4,3,2,1 };
  47. std::cout << MakeHoge2(D) << std::endl;
  48. D = DType{ 3,1,4,1,5,9,2,6,5,3,5 };
  49. std::cout << MakeHoge2(D) << std::endl;
  50. return 0;
  51. }
Success #stdin #stdout 0s 4512KB
stdin
Standard input is empty
stdout
4
-1
2