算法题 趣味算式110
2013-07-04 20:24
302 查看
public class 趣味算式110 { public static void main(String[] args) { char[] cs = new char[17]; for (int i = 0; i != 9; ++i) { cs[2 * i] = (char) (i + 1 + '0'); } // System.out.println(cs); calString(cs, 1); } static int n = 0; public static void calString(char[] s, int pos) { // 插空位置为 1 3 5 7 9 11 13 // 15共八个 if (pos == 15 + 2) { // 此时插空完毕 // try { // FileWriter out = new FileWriter("d:\\1.txt", true); // out.write(s.toString() + " "); // out.close(); // } catch (FileNotFoundException e) { // // TODO Auto-generated catch block // e.printStackTrace(); // } catch (IOException e) { // // TODO Auto-generated catch block // e.printStackTrace(); // } // n++; calResult(new String(s)); return; } for (int i = 0; i != 3; ++i) { // i的0 1 2 分别代表 空 加 减 switch (i) { case 0: s[pos] = ' '; break; case 1: s[pos] = '+'; break; case 2: s[pos] = '-'; break; } calString(s, pos + 2); } } static void calResult(String s) { if (s.equals("")) return; s = s.replaceAll(" ", ""); String data = s; String[] ss = s.split("[^0-9]"); int sum = Integer.parseInt(ss[0]); for (int i = 0; i != ss.length - 1; ++i) { char op = s.charAt(ss[i].length()); if (op == '+') { sum += Integer.parseInt(ss[i + 1]); } else { sum -= Integer.parseInt(ss[i + 1]); } s = s.substring(ss[i].length() + 1); } if (sum == 100) { System.out.println(data + "=100"); } } }
相关文章推荐
- acm算法--每日一题c语言1(趣味算式)
- “趣味算式”——匪警请拨110……蓝桥杯
- 2013-11-06 实验之趣味110算式(递归求解思维)
- 趣味算式 蓝桥杯 110 递归
- 趣味算式填符号
- 趣味算法之兔子产子问题
- 算法训练 最大的算式
- 算法训练 最大的算式
- 趣味算法之趣味素数
- 趣味问题(1 2 3 4 5 6 7 8 9 = 110)
- 算法训练:让结果等于110
- 趣味数学问题的算法实现
- 【算法】算法中的趣味数学(二)
- 趣味算法-三色旗
- 趣味算法-打印数字 (1)
- 算法笔记_057-蓝桥杯练习 最大的算式 (Java)
- 算法练习-猜算式
- Scalaz(31)- Free :自由数据结构-算式和算法的关注分离
- 软件大赛--趣味算式
- 趣味算法之泊松分酒