Advertisement
ogv

Untitled

ogv
Dec 2nd, 2022
14
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.03 KB | None | 0 0
  1. #include <iostream>
  2. #include <limits>
  3. #include <queue>
  4. #include <unordered_map>
  5. #include <fstream>
  6. #include <vector>
  7. #include <string>
  8.  
  9. using namespace std;
  10.  
  11. enum Move {Rock, Paper, Scissors};
  12.  
  13. enum Result { First, Second, Draw};
  14.  
  15. const static unordered_map<string, Move> symbolMap = {
  16. {"A", Move::Rock},
  17. {"B", Move::Paper},
  18. {"C", Move::Scissors},
  19. };
  20.  
  21.  
  22. const static unordered_map<string, Result> resultMap = {
  23. {"X", Result::Second},
  24. {"Y", Result::Draw},
  25. {"Z", Result::First},
  26. };
  27.  
  28. // second => result => first
  29. const static unordered_map<Move, unordered_map<Result, Move>> rules = {
  30. {
  31. Move::Rock, {
  32. { Result::Draw, Move::Rock },
  33. { Result::First, Move::Paper},
  34. { Result::Second, Move::Scissors }
  35. }
  36. },
  37. {
  38. Move::Paper, {
  39. { Result::Draw, Move::Paper },
  40. { Result::First, Move::Scissors},
  41. { Result::Second, Move::Rock }
  42. }
  43. },
  44. {
  45. Move::Scissors, {
  46. { Result::Draw, Move::Scissors },
  47. { Result::First, Move::Rock},
  48. { Result::Second, Move::Paper }
  49. }
  50. }
  51. };
  52.  
  53. int moveScore(Move move) {
  54. switch (move) {
  55. case Move::Rock: return 1;
  56. case Move::Paper: return 2;
  57. case Move::Scissors: return 3;
  58. }
  59. throw "oops";
  60. }
  61.  
  62. int resultScore(Result result) {
  63. switch (result) {
  64. case Result::First: return 6;
  65. case Result::Second: return 0;
  66. case Result::Draw: return 3;
  67. }
  68. throw "oops";
  69. }
  70.  
  71. int main()
  72. {
  73. fstream in("input_test");
  74.  
  75. string s;
  76. int score = 0;
  77. while (in.peek() != EOF) {
  78. in >> s;
  79. auto opponent = symbolMap.find(s)->second;
  80.  
  81. in >> s;
  82. auto result = resultMap.find(s)->second;
  83.  
  84. auto you = rules.find(opponent)->second.find(result)->second;
  85.  
  86. score += moveScore(you);
  87. score += resultScore(result);
  88. }
  89. cout << score << endl;
  90. }
  91.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement