TOPIC

Java 10% wa

Mateus asked 1 year ago

import java.io.IOException;
import java.util.Scanner;
import java.util.Stack;

public class Main {

    public static void main(String[] args) throws IOException {
        int diamond = 0;
        Stack<Character> pilha = new Stack<>();
        Scanner scan = new Scanner(System.in);
        int qtd = scan.nextInt();

        for (int i = 0; i < qtd; i++) {
            String expr = scan.next();
            for (int j = 0; j < expr.length(); j++) {
                if(expr.charAt(j) == '<'){
                    pilha.push(expr.charAt(j));
                }else{
                    if(expr.charAt(j) == '>'){
                        if(!pilha.isEmpty()){
                            pilha.pop();
                            diamond++;
                        }
                    }
                }
            }
            System.out.println(diamond);
            diamond = 0;
        } 
    }

}

This topic has not been answered yet. Be the first!

Remember not post solutions. Your post may be reviewed by our moderators.