2011年2月18日金曜日

Aizu Online Judge 0139 Snakes

■0139 Snakes

正規表現を使って判定すれば簡単.

  1. import java.util.*;  
  2. import java.util.regex.Matcher;  
  3. import java.util.regex.Pattern;  
  4. import java.lang.*;  
  5. import java.math.*;  
  6. import java.io.*;  
  7.   
  8. import static java.lang.Math.*;  
  9. import static java.util.Arrays.*;  
  10.   
  11. public class Main{  
  12.   
  13.  Scanner sc=new Scanner(System.in);  
  14.   
  15.  int INF=1<<28;  
  16.  double EPS=1e-9;  
  17.   
  18.  void run(){  
  19.   for(int n=sc.nextInt(); n>0; n--){  
  20.    String s=sc.next();  
  21.    Matcher m=Pattern.compile("^>'(=+)#(=+)~$").matcher(s);  
  22.    if(m.find()){  
  23.     if(m.group(1).length()==m.group(2).length()){  
  24.      println("A");  
  25.      continue;  
  26.     }  
  27.    }  
  28.    m=Pattern.compile("^>\\^(Q=)+~~$").matcher(s);  
  29.    if(m.find()){  
  30.     println("B");  
  31.     continue;  
  32.    }  
  33.    println("NA");  
  34.   }  
  35.  }  
  36.   
  37.  void debug(Object... os){  
  38.   System.err.println(Arrays.deepToString(os));  
  39.  }  
  40.   
  41.  void print(String s){  
  42.   System.out.print(s);  
  43.  }  
  44.   
  45.  void println(String s){  
  46.   System.out.println(s);  
  47.  }  
  48.   
  49.  public static void main(String[] args){  
  50.   // System.setOut(new PrintStream(new BufferedOutputStream(System.out)));  
  51.   new Main().run();  
  52.  }  
  53. }  

0 件のコメント: