fork download
  1. using System;
  2. using System.IO;
  3. using System.Linq;
  4. using System.Collections;
  5. using System.Collections.Generic;
  6.  
  7. public abstract class Hand : IComparable
  8. {
  9. public abstract String SuperiorName{ get; }
  10.  
  11. public int CompareTo(object other)
  12. {
  13. String otherName = other.ToString();
  14. if (otherName == this.ToString())
  15. return 0;
  16. else if (otherName == this.SuperiorName)
  17. return -1;
  18. else
  19. return 1;
  20. }
  21. }
  22.  
  23. public class Gu : Hand
  24. {
  25. override public String SuperiorName{ get { return "パー"; } }
  26. override public String ToString(){ return "グー"; }
  27. }
  28.  
  29. public class Choki : Hand
  30. {
  31. override public String SuperiorName{ get { return "グー"; } }
  32. override public String ToString(){ return "チョキ"; }
  33. }
  34.  
  35. public class Pa : Hand
  36. {
  37. override public String SuperiorName{ get { return "チョキ"; } }
  38. override public String ToString(){ return "パー"; }
  39. }
  40.  
  41. public class Test
  42. {
  43. public static void Main()
  44. {
  45. int numOfPlayers;
  46. if (!Int32.TryParse(Console.ReadLine(), out numOfPlayers))
  47. {
  48. numOfPlayers = 2;
  49. }
  50. int numOfMatches;
  51. if (!Int32.TryParse(Console.ReadLine(), out numOfMatches))
  52. {
  53. numOfMatches = 3;
  54. }
  55. var availableHands = new Hand[]{new Gu(), new Choki(), new Pa()};
  56. var rand = new Random();
  57. for (int cnt = 0; cnt < numOfMatches; cnt++) {
  58. var players = new Hand[numOfPlayers];
  59. for (int i = 0; i < numOfPlayers; i++) {
  60. var player = availableHands[rand.Next(3)];
  61. Console.WriteLine($"プレーヤー{i + 1}:{player}");
  62. players[i] = player;
  63. }
  64. if (new HashSet<Hand>(players).Count != 2)
  65. {
  66. Console.WriteLine("引き分けです");
  67. }
  68. else
  69. {
  70. var winner = players.Max();
  71. var winnerIndices = new List<string>();
  72. for (int idx = 0; idx < numOfPlayers; idx++)
  73. {
  74. if (players[idx] == winner)
  75. {
  76. winnerIndices.Add((idx + 1).ToString());
  77. }
  78. }
  79. Console.WriteLine($"プレイヤー{String.Join(", ", winnerIndices)}の勝ちです");
  80. }
  81. Console.WriteLine();
  82. }
  83. }
  84. }
Success #stdin #stdout 0.06s 24216KB
stdin
4
5
stdout
プレーヤー1:グー
プレーヤー2:チョキ
プレーヤー3:パー
プレーヤー4:パー
引き分けです

プレーヤー1:グー
プレーヤー2:グー
プレーヤー3:パー
プレーヤー4:パー
プレイヤー3, 4の勝ちです

プレーヤー1:グー
プレーヤー2:グー
プレーヤー3:グー
プレーヤー4:チョキ
プレイヤー1, 2, 3の勝ちです

プレーヤー1:チョキ
プレーヤー2:チョキ
プレーヤー3:グー
プレーヤー4:パー
引き分けです

プレーヤー1:グー
プレーヤー2:チョキ
プレーヤー3:グー
プレーヤー4:グー
プレイヤー1, 3, 4の勝ちです