fork download
  1. #include <iostream>
  2. #include <vector>
  3. #include <map>
  4.  
  5. enum class Mode {
  6. EQ = -1,
  7. AS = -2,//昇順
  8. DES = -3,//降順
  9. NotGood = -4,
  10. Zero=0,
  11. };
  12.  
  13. int SortedType(const std::vector<int>& vec){
  14.  
  15. std::map < Mode, int > M = {{ Mode::EQ, 1 }, { Mode::DES, 1}, { Mode::AS, 1 }, };
  16.  
  17. if (vec.size() < 2) return static_cast<int>(Mode::EQ);
  18. bool IsUpper = false;
  19. std::size_t i = 0;
  20. int OR = 0;
  21.  
  22. for (i = 1; i < vec.size(); i++){
  23.  
  24. if ((vec[i - 1] != vec[i])) M[Mode::EQ] = 0;
  25. if ((vec[i - 1] > vec[i])) M[Mode::AS] = 0;
  26. if ((vec[i - 1] < vec[i])) M[Mode::DES] = 0;
  27.  
  28. for (auto& o : M) OR |= o.second;
  29. if (OR == 0) return i;
  30. OR = 0;
  31. }
  32. if (M[Mode::EQ] == 1) return static_cast<int>(Mode::EQ);
  33. if (M[Mode::DES] == 1) return static_cast<int>(Mode::DES);
  34. if (M[Mode::AS] == 1) return static_cast<int>(Mode::AS);
  35.  
  36. return static_cast<int>(Mode::NotGood);
  37. }
  38.  
  39. bool Judge(const std::vector<int>& vec, int N){
  40.  
  41. std::cout <<'[';
  42. for (auto& o : vec) std::cout << o << ',';
  43. std::cout <<']';
  44. if (N == static_cast<int>(Mode::EQ)) std::cout << " = > " << "EQ" << std::endl;
  45. if (N == static_cast<int>(Mode::AS)) std::cout << " = > " << "AS" << std::endl;
  46. if (N == static_cast<int>(Mode::DES)) std::cout << " = > " << "DES" << std::endl;
  47. if (N >=0) std::cout << " = > " << N << std::endl;
  48.  
  49. return true;
  50. }
  51.  
  52. int main(){
  53.  
  54. int R = 0;
  55. std::vector<int> vec;
  56.  
  57. vec = { 6, 6, 3, 2, 6, 4, 7, 4, 7, 4 };
  58. R= SortedType(vec);// = > 4
  59. Judge(vec, R);
  60.  
  61. vec = { 2, 3, 4, 4, 4, 6, 6, 6, 7, 7 };// = > AS
  62. R= SortedType(vec);// = > 4
  63. Judge(vec, R);
  64.  
  65. vec = { 7, 7, 6, 6, 6, 4, 4, 4, 3, 2 };// = > DES
  66. R= SortedType(vec);// = > 4
  67. Judge(vec, R);
  68.  
  69. vec={1, 1, 1, 1, 1, 1, 1, 1, 1, 1};// = > EQ
  70. R= SortedType(vec);// = > 4
  71. Judge(vec, R);
  72.  
  73. vec={};// = > EQ
  74. R= SortedType(vec);// = > 4
  75. Judge(vec, R);
  76.  
  77. vec={ 1 };// = > EQ)
  78. R= SortedType(vec);// = > 4
  79. Judge(vec, R);
  80.  
  81. return 0;
  82. }
Success #stdin #stdout 0s 3476KB
stdin
Standard input is empty
stdout
[6,6,3,2,6,4,7,4,7,4,] = > 4
[2,3,4,4,4,6,6,6,7,7,] = > AS
[7,7,6,6,6,4,4,4,3,2,] = > DES
[1,1,1,1,1,1,1,1,1,1,] = > EQ
[] = > EQ
[1,] = > EQ