Hi
I've seen all post in this forum and tried every input people told albout and got the rigth output, but the judge keeps saying my answer is not correct.
Can anyone help me?
here is my code:
[java]
import java.io.*;
class Main{
public static void main(String args[]){
String s;
//read the number of inputs
int n = Integer.parseInt(ReadLn(25).trim());
//for each input
for(int x=0; x<n; x++) {
//read the string
s = ReadLn(135).trim();
//if the number of elements is odd
if (s.length() % 2 != 0)
System.out.println("No"); //then it's incorrect
else {
//go through all caracters from the string
for(int i=0;i<s.length()-1;i++) {
//if the sequences () or [] exist in the string
if((s.charAt(i)== '(' && s.charAt(i+1) == ')') ||
(s.charAt(i)== '[' && s.charAt(i+1) == ']')){
//remove them
s = s.substring(0,i) + s.substring(i+2);
//and start from the beggining
i=0;
}
}
if(s.equals("") || s.equals("()") || s.equals("[]"))
System.out.println("Yes");
else
System.out.println("No");
}
}
}
static String ReadLn (int maxLg) // utility function to read from stdin
{
byte lin[] = new byte [maxLg];
int lg = 0, car = -1;
String line = "";
try
{
while (lg < maxLg)
{
car = System.in.read();
if ((car < 0) || (car == '\n')) break;
lin [lg++] += car;
}
}
catch (IOException e)
{
return (null);
}
if ((car < 0) && (lg == 0)) return (null); // eof
return (new String (lin, 0, lg));
}
}[/java]
