import java.util.Scanner; public class Demo1 { public static void main(String[] args) { System.out.println("********** 请输入初始字符串 ************"); Scanner input = new Scanner(System.in); String str = input.next(); for(int i = 0; i <= str.length(); i++) { String player = ""; if(i%2 == 0) { player = "A"; } else { player = "B"; } System.out.println("**********"+player+" 开始输入: ************"); Scanner inputs = new Scanner(System.in); String a1 = inputs.next(); str = deleteString(str, a1); if(isSort(str)) { if(player == "A") { System.out.println("***A---1***"); } else { System.out.println("***B---2***"); } break; } System.out.println(str.length()); System.out.println(str); } System.out.println(str); } public static String deleteString(String str, String input) { int index = str.indexOf(input); if(index != -1) { str = str.replaceAll(input, ""); str = str.substring(0,index) + str.substring(index); } return str; } public static Boolean isSort(String str) { for(int i = 1; i <= str.length(); i++) { for(int j=i+1 ; j <= str.length(); j++) { if((int)str.substring(j-1,j).toCharArray()[0] < (int)str.substring(i-1,i).toCharArray()[0]) { return false; } else { continue; } } } return true; } }
单词博弈的思考
时间: 2024-10-12 19:26:38