Poj-1686

题目链接:http://poj.org/problem?id=1686
hint:考察 四则运算 ,用堆栈模拟 ,不过这里有个简便方法 。

public static void main(String args[]) throws ScriptException {    
        Scanner cin  = new Scanner(System.in);
        ScriptEngineManager manage = new ScriptEngineManager();
        ScriptEngine engine = manage.getEngineByName("JavaScript");
        while (cin.hasNext()) {
            int n = cin.nextInt();
            String s1 = cin.nextLine();
            String s2;
            while(n-->0){
                s1 = cin.nextLine();
                s2 = cin.nextLine();
                for(char i='a';i<='z';i++){
                    s1 = s1.replace(""+i, String.valueOf((int)i));
                    s2 = s2.replace(""+i, String.valueOf((int)i));
                }
                System.out.println(engine.eval(s1).equals(engine.eval(s2)) ?"YES":"NO");
            }
        }
    }

你可能感兴趣的:(Poj-1686)