或什么都不插入,使得计算结果总是100的程序,并输出所有的可能

import java.util.ArrayList;import java.util.List;/** * 1、2、2、3、4、5这六个数字,用java写一个main函数,打印出所有不同的排列,, 如:512234、412345等.要求:"4"不能在第三位,"3"与"5"不能相连. * * @author gnn */public class TryTest {public static List<String> list = new ArrayList<String>();public static int num = 8 ;/**     * 构造字符串的所有排序组合     * @param str 将要组合成的字符     * @param nstr 源字符串集     */public static void group(String str, String nstr) {String temp = "";addStr(temp, "+");addStr(temp, "-");addStr(temp, "o");}public static void addStr(String str, String nstr) {if (num != str.length()) {String temp = "";temp = str + nstr;if (temp.length() == num){list.add(temp);}System.out.println(temp);addStr(temp, "+");addStr(temp, "-");addStr(temp, "o");}}public static void main(String[] args) {TryTest.group("", "+-o");System.out.println(list.size());}

}

import java.util.ArrayList; import java.util.List; import java.util.EmptyStackException; public class MyStack<E extends Object> { private List<E> pool = new ArrayList<E>(); public MyStack() { } public void clear() { pool.clear(); } public boolean isEmpty() { return pool.isEmpty(); } /** * 获取栈顶元素 * */ public E getTopObjcet() { if (isEmpty()) {return null;} return pool.get(0); } /** * 弹出栈操作 * */ public E pop() { if (isEmpty()) {throw new EmptyStackException();} return pool.remove(pool.size() – 1); } /** * 压入栈 * */ public void push(E e) { //if (isEmpty()) {throw new EmptyStackException();} pool.add(e); } /** * 获取当前栈大小 * */ public int getStatckSize() { //if (isEmpty()) {throw new EmptyStackException();} return pool.size(); } }

import java.util.ArrayList;import java.util.List;public class Question {private static List<Integer> sumList = new ArrayList<Integer>() ;public static void main(String[] args) {TryTest.group("", "+-o");System.out.println(TryTest.list.size());new Question().init();System.out.println(sumList.size());int max = new Question().sort();System.out.println("max:"+max);int min = new Question().getMin();System.out.println("min:"+min);}public void init() {this.operate();}public void operate() {MyStack<Integer> intStack = new MyStack<Integer>();MyStack<String> strStack = new MyStack<String>();for (int i = 0 ; i < TryTest.list.size(); i++) {intStack.clear();strStack.clear();for (int t = 9 ; t > 0 ; t–) {intStack.push(t);}for (int j = TryTest.list.get(i).length() ; j > 0 ; j–) {strStack.push(TryTest.list.get(i).substring(j-1,j));}this.calculate( intStack , strStack);}}public void calculate(MyStack<Integer> intStack, MyStack<String> strStack) {int size = intStack.getStatckSize();int strStackSize = strStack.getStatckSize();/*for (int i = 0; i < size; i++) {System.out.println(intStack.pop());}*/int temp = intStack.pop();for (int i = 0; i < strStackSize; i++) {switch (strStack.pop()) {case "+":temp+=intStack.pop();break;case "-":temp-=intStack.pop();break;case "o":temp=Integer.parseInt(temp+""+intStack.pop());break;default:break;}}System.out.println(temp);sumList.add(temp);}public int sort(){int max = sumList.get(0) ;for (int i = 0; i < sumList.size()-1; i++) {if(max < sumList.get(i+1)){max = sumList.get(i+1);}}return max;}public int getMin(){int min = sumList.get(0) ;for (int i = 0; i < sumList.size()-1; i++) {if(min > sumList.get(i+1)){min = sumList.get(i+1);}}return min;}}

如果雨后还是雨,如果忧伤过后还是忧伤,

或什么都不插入,使得计算结果总是100的程序,并输出所有的可能

相关文章:

你感兴趣的文章:

标签云: