英语单词玩游戏
来源:互联网 发布:mysql新建数据库命令 编辑:程序博客网 时间:2024/04/29 23:22
甲乙两个人用一个英语单词玩游戏。两个人轮流进行,每个人每次从中删掉任意一个字母,如果剩余的字母序列是严格单调递增的(按字典序a b c ....z),则这个人胜利。两个人都足够聪明,甲先开始,问他能赢么?
public static void main(String[] args) { String str=null; String[] str_arr = null; String jia= null; String yi=null; while(true){ if(str == null){ System.out.println("请输入单词..."); str =new Scanner(System.in).nextLine(); char[] cunnt = str.toCharArray(); str = null; for(char c:cunnt){ if(str == null){ str= ""+c; }else{ str= str + ","+c; } } str_arr = new String[cunnt.length]; str_arr = str.split(","); } if(jia == null){ System.out.println("请输入甲名称..."); jia =new Scanner(System.in).nextLine(); } if(yi == null){ System.out.println("请输入乙单词..."); yi =new Scanner(System.in).nextLine(); } System.out.println("请输入1甲2乙/减去字母的位数..."); String words=new Scanner(System.in).nextLine(); String[] arr =words.split(","); String str_temp = null; for(int i=0;i<str_arr.length;i++){ String c = str_arr[i]; if(i != (new Integer(arr[1]).intValue()-1)){ if(str_temp == null){ str_temp = c; }else{ str_temp = str_temp+","+c; } } } String[] str_temp_arr = str_temp.split(","); String[] cont = new String[]{"a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"}; Set<Integer> one=null; List<Integer> shree=null; for(String str_temp_arr_value:str_temp_arr){ for(int i=0;i<cont.length;i++){ String c =cont[i]; if(c.equals(str_temp_arr_value)){ if(one == null){ one=new TreeSet<Integer>(); one.add(i); }else{ if(one.contains(i)){ if(shree == null){ shree=new ArrayList<Integer>(); } shree.add(i); }else{ one.add(i); } } } } } if(shree == null ){ StringBuffer two = null; Iterator<Integer> ite = one.iterator(); while(ite.hasNext()){ if(two == null){ two=new StringBuffer(); two.append(cont[ite.next()]); }else{ two.append(",").append(cont[ite.next()]); } } String jia_s = arr[0]; if(jia_s.equals(jia)){ if(str_temp.length() == 1){ System.out.print(jia_s+"获得胜利,当前单词为:"+str_temp); break; }else if(str_temp.equals(two.toString())){ System.out.print(jia_s+"获得胜利,当前单词为:"+str_temp); break; } }else if(jia_s.equals(yi)){ if(str_temp.length() == 1){ System.out.print(jia_s+"获得胜利,当前单词为:"+str_temp); break; }else if(str_temp.equals(two.toString())){ System.out.print(jia_s+"获得胜利,当前单词为:"+str_temp); break; } } } System.out.println("当前单词还剩下:"+str_temp); str = str_temp; str_arr = str_temp.split(","); } }
0 0
- 英语单词玩游戏
- 边玩游戏边学英语单词.
- 游戏英语单词
- 英语单词拼写游戏开发纪录
- 玩游戏
- 玩游戏
- 玩游戏
- 玩游戏
- 英语单词
- 英语单词
- 英语单词
- 英语单词
- 英语单词
- 英语单词
- 英语单词
- 英语单词
- 英语单词
- 英语单词
- Phoenix Framework 创建用例时需要关注的事项
- android router
- HTTP——Web服务器、代理、缓存
- Spring连接MySQL、Oracle和SQL Server的数据库运动连接属性
- 加随机数引入脚本
- 英语单词玩游戏
- synchronized
- 使用 eclipse 创建 Maven 工程及其子模块
- 正则表达式语法
- html table表头排序功能
- JavaScript表单验证中文大写字母
- 软件测试面试 (二) 如何测试网页的登录页面
- 【学习笔记】〖九度OJ〗题目1156:谁是你的潜在朋友
- websphere和tomcat在使用中的区别