1.3背包,队列和栈 (Part1 -- Exercises)

State:Updating


第一题

    public boolean isFull(){
        N == a.length;
    }

第三题

b f g

第四题

package com.chen_swe;

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.Stack;

/**
 * Created by chen_swe on 3/17/16.
 */
public class Parentheses {
    public static void main(String[] args)
            throws IOException {

        try(BufferedReader reader = new BufferedReader(
                new FileReader("input.txt"))) {

            Stack stack = new Stack<>();
            int ch;

            while ((ch = reader.read()) != -1) {
                System.out.format("%c",(char)ch);
                switch ((char) ch) {
                    case '(':
                    case '[':
                    case '{':
                        stack.push((char) ch);
                        break;
                    case ')':
                        if (stack.pop() != '(') System.exit(1);
                        break;
                    case ']':
                        if (stack.pop() != '[') System.exit(1);
                        break;
                    case '}':
                        if (stack.pop() != '{') System.exit(1);
                        break;
                    default:
                        break;
                }
            }
        }catch (IOException x){
            System.err.println(x.getMessage());
        }
        System.out.println(true);
    }
}

你可能感兴趣的:(算法,4e,solution,1-3)