题目:略
分析:
1.建立猜拳二维表:剪刀、石头、布->0,1,2
2.将猜拳符号转化为下标。
3.分别计算牛妹出左手和出右手的概率。
code:
1 import java.util.*; 2 3 public class Main { 4 public static void main(String args[]) { 5 Scanner read = new Scanner(System.in); 6 int n = read.nextInt() 7 //猜拳表 8 int dp[][] = {{-1, -1, 1}, {1, -1, -1}, {-1, 1, -1}}; 9 int x1, x2, y1, y2; 10 int left = 0; 11 int right = 0; 12 read.nextLine(); 13 for (int i = 0; i < n; i++) { 14 String line = read.nextLine(); 15 String[] ss = line.split("\s+"); 16 //获取下标 17 x1 = getIndex(ss[0]); 18 x2 = getIndex(ss[1]); 19 y1 = getIndex(ss[2]); 20 y2 = getIndex(ss[3]); 21 //计算出左手赢得概率 22 left = dp[x1][y1] + dp[x1][y2]; 23 //计算出右手赢得改了吧 24 right = dp[x2][y1] + dp[x2][y2]; 25 //根据计算结果判断 26 if (left > right) { 27 System.out.println("left"); 28 } else if (left == right) { 29 System.out.println("same"); 30 } else { 31 System.out.println("right"); 32 } 33 } 34 } 35 //根据传入的值返回下标 36 public static int getIndex(String s) { 37 if ("J".equals(s)) { 38 return 0; 39 } else if ("S".equals(s)) { 40 return 1; 41 } else { 42 return 2; 43 } 44 } 45 46 }