Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * Created by Thomas Boulbes
- */
- import java.io.BufferedReader;
- import java.io.IOException;
- import java.io.InputStreamReader;
- import java.io.PrintWriter;
- import java.util.StringTokenizer;
- // TODO: Auto-generated Javadoc
- /**
- * The Class Main.
- */
- public class Main {
- /**
- * The main method.
- *
- * @param args
- * the arguments
- * @throws IOException
- * Signals that an I/O exception has occurred.
- */
- public static void main(String[] args) throws IOException {
- FastReader r = new FastReader();
- PrintWriter stdout = new PrintWriter(System.out);
- int T = r.nextInt();
- while (T-- > 0) {
- int n = r.nextInt() - 1;
- String[] s = r.nextLine().split("\\s+");
- int m = r.nextInt() - 1;
- String[] f = r.nextLine().split("\\s+");
- boolean b = false;
- while (n >= m && !b) {
- int i = n, j = m;
- b = s[i].equals(f[j]);
- while (b && j > 0) {
- i--;
- j--;
- b = s[i].equals(f[j]);
- }
- n--;
- }
- stdout.println(b ? "Yes" : "No");
- }
- stdout.flush();
- stdout.close();
- }
- //////////////////////////////////////////////////
- ////////////////// +--------+ ////////////////////
- ////////////////// | READER | ////////////////////
- ////////////////// +--------+ ////////////////////
- //////////////////////////////////////////////////
- static class FastReader {
- BufferedReader br;
- StringTokenizer st;
- public FastReader() {
- br = new BufferedReader(new InputStreamReader(System.in));
- }
- String next() {
- while (st == null || !st.hasMoreElements()) {
- try {
- st = new StringTokenizer(br.readLine());
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- return st.nextToken();
- }
- int nextInt() {
- return Integer.parseInt(next());
- }
- long nextLong() {
- return Long.parseLong(next());
- }
- double nextDouble() {
- return Double.parseDouble(next());
- }
- String nextLine() {
- String str = "";
- try {
- str = br.readLine();
- } catch (IOException e) {
- e.printStackTrace();
- }
- return str;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement