Advertisement
Guest User

Untitled

a guest
May 26th, 2017
549
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.08 KB | None | 0 0
  1.  
  2. /*
  3.  * Created by Thomas Boulbes
  4.  */
  5. import java.io.BufferedReader;
  6. import java.io.IOException;
  7. import java.io.InputStreamReader;
  8. import java.io.PrintWriter;
  9. import java.util.StringTokenizer;
  10.  
  11. // TODO: Auto-generated Javadoc
  12. /**
  13.  * The Class Main.
  14.  */
  15. public class Main {
  16.  
  17.     /**
  18.      * The main method.
  19.      *
  20.      * @param args
  21.      *            the arguments
  22.      * @throws IOException
  23.      *             Signals that an I/O exception has occurred.
  24.      */
  25.     public static void main(String[] args) throws IOException {
  26.         FastReader r = new FastReader();
  27.         PrintWriter stdout = new PrintWriter(System.out);
  28.         int T = r.nextInt();
  29.         while (T-- > 0) {
  30.             int n = r.nextInt() - 1;
  31.             String[] s = r.nextLine().split("\\s+");
  32.             int m = r.nextInt() - 1;
  33.             String[] f = r.nextLine().split("\\s+");
  34.             boolean b = false;
  35.             while (n >= m && !b) {
  36.                 int i = n, j = m;
  37.                 b = s[i].equals(f[j]);
  38.                 while (b && j > 0) {
  39.                     i--;
  40.                     j--;
  41.                     b = s[i].equals(f[j]);
  42.                 }
  43.                 n--;
  44.             }
  45.             stdout.println(b ? "Yes" : "No");
  46.         }
  47.         stdout.flush();
  48.         stdout.close();
  49.     }
  50.  
  51.     //////////////////////////////////////////////////
  52.     ////////////////// +--------+ ////////////////////
  53.     ////////////////// | READER | ////////////////////
  54.     ////////////////// +--------+ ////////////////////
  55.     //////////////////////////////////////////////////
  56.  
  57.     static class FastReader {
  58.         BufferedReader br;
  59.         StringTokenizer st;
  60.  
  61.         public FastReader() {
  62.             br = new BufferedReader(new InputStreamReader(System.in));
  63.         }
  64.  
  65.         String next() {
  66.             while (st == null || !st.hasMoreElements()) {
  67.                 try {
  68.                     st = new StringTokenizer(br.readLine());
  69.                 } catch (IOException e) {
  70.                     e.printStackTrace();
  71.                 }
  72.             }
  73.             return st.nextToken();
  74.         }
  75.  
  76.         int nextInt() {
  77.             return Integer.parseInt(next());
  78.         }
  79.  
  80.         long nextLong() {
  81.             return Long.parseLong(next());
  82.         }
  83.  
  84.         double nextDouble() {
  85.             return Double.parseDouble(next());
  86.         }
  87.  
  88.         String nextLine() {
  89.             String str = "";
  90.             try {
  91.                 str = br.readLine();
  92.             } catch (IOException e) {
  93.                 e.printStackTrace();
  94.             }
  95.             return str;
  96.         }
  97.     }
  98.  
  99. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement