Quantcast
Channel: CodeChef Discuss - latest questions
Viewing all articles
Browse latest Browse all 40121

Compiler and Parsers

$
0
0

Why my code says WA i cannot get. Please Help

import java.io.*;



class Compiler

{

    static String a[];
    static int pos;

    public static void main(String args[])throws Exception
    {

        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
        int t=Integer.parseInt(br.readLine());

        for(int z=0;z<t;z++) {
            a=new String[1000000];
            long l=0;
            pos=0;
            String s=br.readLine();
            for(int i=0;i<s.length();i++) {
                if(s.charAt(i)=='<')push(""+s.charAt(i));
                else {
                    if(pos>0) {
                        String k=pop()+">";
                        l=Math.max(l,k.length());
                        if(pos>0)a[pos-1]=a[pos-1]+k;
                    }
                }
            }
            System.out.println(l);


        }

    }
    static void push(String s) {
        a[pos++]=s;
    }
    static String pop() {
        String k=a[pos-1];
        a[pos-1]=null;
        pos--;
        return k;
    }

}

Viewing all articles
Browse latest Browse all 40121

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>