fork download
  1. #include <iostream>
  2. #include <map>
  3. #include <cstdint>
  4. #include <tuple>
  5. #include <string>
  6.  
  7. static const char pa = 'p';
  8. static const char gu = 'g';
  9. static const char choki = 'c';
  10.  
  11. typedef std::tuple<std::string, std::uint64_t> RType;
  12. typedef std::map<char, std::uint64_t> MType;
  13.  
  14. RType MakeHoge(std::string s){
  15. bool P = false;
  16. bool G = false;
  17. bool C = false;
  18. MType M;
  19.  
  20. for(auto& o : s){
  21. M[o]++;
  22. if (o == pa) P = true;
  23. if (o == gu) G = true;
  24. if (o == choki)C = true;
  25. }
  26. if (P & !G & !C) return std::make_tuple("PNone", M[pa]);
  27. if (!P & G & !C) return std::make_tuple("GNone", M[gu]);
  28. if (!P & !G & C) return std::make_tuple("CNone", M[choki]);
  29. if (P & G & C) return std::make_tuple("None", 0);
  30. if (P & G) return std::make_tuple("P", M[pa]);
  31. if (G & C) return std::make_tuple("G", M[gu]);
  32. if (C & P) return std::make_tuple("C", M[choki]);
  33.  
  34. return std::make_tuple("Error", -1);
  35.  
  36.  
  37. }
  38. bool Show(std::string str, RType R){
  39. std::string S;
  40. std::uint64_t N;
  41.  
  42. std::tie(S, N) = R;
  43.  
  44. std::cout << str << " -> " << S << '@' << N << std::endl;
  45.  
  46. return true;
  47. }
  48.  
  49. int main(){
  50. std::string S;
  51. RType R;
  52.  
  53. S = "gpgpgppppg";
  54. R = MakeHoge(S);
  55. Show(S, R);
  56. S = "gcgcgcgcgcggcgccgcgcg";
  57. R = MakeHoge(S);
  58. Show(S, R);
  59. S = "ccpcpppcccpppcppcpcc";
  60. R = MakeHoge(S);
  61. Show(S, R);
  62. S = "ggcgcgcggggcpgcggcgcggggcgcgcc";
  63. R = MakeHoge(S);
  64. Show(S, R);
  65. S = "ppp";
  66. R = MakeHoge(S);
  67. Show(S, R);
  68. S = "cccc";
  69. R = MakeHoge(S);
  70. Show(S, R);
  71. S = "gggggg";
  72. R = MakeHoge(S);
  73. Show(S, R);
  74. return 0;
  75. }
Success #stdin #stdout 0s 3280KB
stdin
Standard input is empty
stdout
gpgpgppppg -> P@6
gcgcgcgcgcggcgccgcgcg -> G@11
ccpcpppcccpppcppcpcc -> C@10
ggcgcgcggggcpgcggcgcggggcgcgcc -> None@0
ppp -> PNone@3
cccc -> CNone@4
gggggg -> GNone@6