fork download
  1. // annkasep.cpp : アプリケーションのエントリ ポイントを定義します。
  2. //
  3. #include <iostream>
  4. #include <tuple>
  5. #include <vector>
  6. #include <cstdint>
  7. #include <string>
  8. #include <sstream>
  9. #include <cctype>
  10. #include <algorithm>
  11.  
  12. typedef std::tuple < std::int64_t, std::int64_t> DType;
  13. typedef std::vector<DType> RType;
  14. typedef std::vector<std::int64_t> ExType;
  15.  
  16. //http://m...content-available-to-author-only...h.net/test/read.cgi/tech/1514772904/41 get license.it is GPL v3.
  17.  
  18. std::size_t FindDigit(const std::string& S,std::size_t F) {
  19. for (std::size_t i = F; i < S.size(); i++) {
  20. if (std::isdigit(S[i])) {
  21. return i;
  22. }
  23. if (S[i] == ',') {
  24. return i;
  25. }
  26. }
  27. return S.npos;
  28. }
  29.  
  30. std::string ConsumeDigit(const std::string& s){
  31. std::size_t i = 0;
  32. for (i = 0; i < s.size(); i++) {
  33. if (!std::isdigit(s[i])&&s[i]!=',')break;
  34. }
  35. return s.substr(i, s.size() - i);
  36. }
  37.  
  38. std::string Replace(std::string& s,char from,char To){
  39. std::size_t p = 0;
  40. while ((p=s.find(from, 0)) != s.npos) {
  41. s = s.replace(p, 1, std::string{ To });
  42. }
  43.  
  44. return s;
  45. }
  46.  
  47.  
  48. RType MakeHoge(std::string s) {
  49. std::size_t p=0;
  50. std::size_t l = 0;
  51. std::int64_t F = 0;
  52. std::int64_t E = 0;
  53. bool F1 = false;
  54. bool F2 = false;
  55. RType R;
  56. s = Replace(s, '-', '*');//*は適当
  57. while(s.size()!=0) {
  58. p = 0;
  59. if (s[0] == ',')p++;
  60. l = s.find_first_of(",", p);
  61. if (l == s.npos)l = s.size();
  62. std::string t = s.substr(p, l);
  63. s = s.substr(l, s.size() - l);
  64. t += ',';
  65.  
  66. F1 = false;
  67. F2 = false;
  68. while ((p = FindDigit(t, 0)) != std::string::npos) {
  69. if (t[p] != ',') {
  70.  
  71. t = t.substr(p, t.size() - p);
  72. std::stringstream ss;
  73. ss << t;
  74.  
  75. if (F1 == false) {
  76. ss >> F;
  77. F1 = true;
  78. F2 = true;
  79. }
  80. else {
  81. ss >> E;
  82. F1 = false;
  83. }
  84. }
  85. t = ConsumeDigit(t);
  86. }
  87. if (F2) {
  88. if (F1 == true) E = F;
  89. if (E < F)std::swap(F, E);
  90. R.push_back({ F,E });
  91. }
  92. }
  93.  
  94. return R;
  95. }
  96.  
  97. std::vector<std::int64_t> ExAnka(const RType& R,std::int64_t F,std::int64_t E) {
  98. std::vector<std::int64_t> v;
  99. for (auto o : R) {
  100. for (std::int64_t i = std::get<0>(o); i <= std::get<1>(o); i++) {
  101. if (i <= F)continue;
  102. if (i > E)continue;
  103. v.push_back(i);
  104. }
  105. }
  106. std::sort(v.begin(), v.end());
  107. v.erase(std::unique(v.begin(), v.end()), v.end());
  108.  
  109. return v;
  110. }
  111.  
  112. bool show(const RType& R) {
  113. for (auto o : ExAnka(R,0,100000)) {
  114.  
  115. std::cout << o << ',';
  116. }
  117.  
  118. std::cout << std::endl;
  119. return true;
  120. }
  121.  
  122. int main()
  123. {
  124. RType R;
  125.  
  126. R=MakeHoge(">>1");
  127. show(R);
  128. R=MakeHoge(">>1-3");
  129. show(R);
  130. R=MakeHoge(">>1,3");
  131. show(R);
  132. R=MakeHoge(">>1-3,5,9-10");
  133. show(R);
  134. R=MakeHoge(">>000000-000000001");//8進数になるかもしれん。
  135. show(R);
  136. R=MakeHoge(">>289494");
  137. show(R);
  138. R=MakeHoge(">>3,0-3,4,5,6,4,2-8");
  139. show(R);
  140. return 0;
  141. }
  142.  
  143.  
Success #stdin #stdout 0s 4500KB
stdin
Standard input is empty
stdout
1,
1,2,3,
1,3,
1,2,3,5,9,10,
1,

1,2,3,4,5,6,7,8,