public void init() {
    Scanner scan = new Scanner(System.in);
    n = scan.nextInt();
    m = scan.nextInt();
    for (int i = 0; i < n; i++) {
      String input = scan.next();
      record.add(input);
    }

    for (int i = 0; i < m; i++) {
      String input = scan.next();
      char[] charArray = input.toCharArray();
      boolean isValid = false;
      for (int j = 0; j < charArray.length; j++) {
        char c = charArray[j];
        for (char d = 'a'; d <= 'c'; d = (char) (d + 1)) {
          if (d == c) continue;
          charArray[j] = d;
          if (record.contains(new String(charArray))) {
            isValid = true;
            break;
          }
        }
        charArray[j] = c;
        if (isValid) break;
      }
      if (isValid) System.out.println("YES");
      else System.out.println("NO");
    }
    scan.close();
  }
 public static void main(String[] args) {
   Scanner inp = new Scanner(System.in);
   int n = inp.nextInt();
   String[] store = new String[n];
   for (int i = 0; i < n; i++) store[i] = inp.next();
   int[] cnt = new int[n];
   Arrays.fill(cnt, 0);
   String str = inp.next();
   for (int j = 0; j < n; j++) {
     int l1 = store[j].length();
     for (int k = 0; k <= (str.length() - l1); k++) {
       if (str.substring(k, k + l1).equals(store[j])) {
         cnt[j] = cnt[j] + 1;
       }
     }
   }
   int y = 0;
   for (int m = 0; m < n; m++) {
     y = Math.max(y, cnt[m]);
   }
   System.out.println(y);
   for (int h = 0; h < n; h++) {
     if (cnt[h] == y) System.out.println(store[h]);
   }
 }
Esempio n. 3
0
 public static void main(String[] args) {
   Scanner s = new Scanner(System.in);
   BigInteger a = new BigInteger(s.next());
   BigInteger b = new BigInteger(s.next());
   BigInteger ad = a.add(b);
   BigInteger mu = a.multiply(b);
   System.out.println(ad);
   System.out.println(mu);
 }
Esempio n. 4
0
 public static void main(String[] args) {
   Scanner in = new Scanner(System.in);
   int m;
   m = in.nextInt();
   String grid[] = new String[m];
   for (int i = 0; i < m; i++) {
     grid[i] = in.next();
   }
   displayPathtoPrincess(m, grid);
 }
 public static void main(String[] args) {
   Scanner in = new Scanner(System.in);
   int t = in.nextInt();
   for (int a0 = 0; a0 < t; a0++) {
     int R = in.nextInt();
     int C = in.nextInt();
     String G[] = new String[R];
     for (int G_i = 0; G_i < R; G_i++) {
       G[G_i] = in.next();
     }
     int r = in.nextInt();
     int c = in.nextInt();
     String P[] = new String[r];
     for (int P_i = 0; P_i < r; P_i++) {
       P[P_i] = in.next();
     }
     // Check Grid
     checkGrid(G, P);
   }
 }
  public static void main(String[] args) {
    Scanner in = new Scanner(System.in);
    String time = in.next();

    // Set format for input and output
    SimpleDateFormat sdf = new SimpleDateFormat("hh:mm:ssa");
    SimpleDateFormat out = new SimpleDateFormat("HH:mm:ss");

    try {
      Date inTime = sdf.parse(time);
      System.out.println(out.format(inTime));
    } catch (ParseException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
  }
Esempio n. 7
0
  public static void main(String[] args) throws IOException {

    Scanner scanner = new Scanner(new BufferedInputStream(System.in));
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

    while (scanner.hasNext()) {
      String str = scanner.next();
      if (str.equals("0")) break;
      Long sum = 0L;

      for (int i = str.length() - 1, j = 1; i >= 0; i--, j++) {
        sum = sum + ((long) Math.pow(2, j) - 1) * ((long) str.charAt(i) - 48);
      }
      System.out.println(sum);
    }
  }
Esempio n. 8
0
 public static void main(String[] args) throws NumberFormatException, IOException {
   Scanner sc = new Scanner(System.in);
   int N = sc.nextInt();
   int M = sc.nextInt();
   int maxValue = (int) Math.pow(2, 5) - 1;
   int[] array = new int[N];
   int first = 0;
   int second = 0;
   for (int i = 0; i < N; i++) {
     array[i] = Integer.parseInt(sc.next(), 2);
   }
   for (int i = 0; i < array.length; i++) {
     for (int j = i + 1; j < array.length; j++) {
       int or = (array[i] | array[j]);
       if (or > first) {
         first = or;
       }
     }
   }
   System.out.println(first + " " + second);
 }
Esempio n. 9
0
  public static void main(String[] args) {
    /* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution. */
    Scanner sc = new Scanner(System.in);
    String s1 = sc.next();
    String s2 = sc.next();

    int[][] f = new int[s1.length()][s2.length()];

    for (int i = 0; i < s1.length(); i++) {
      for (int j = 0; j < s2.length(); j++) {
        f[i][j] = 0;
      }
    }

    for (int i = 0; i < s1.length(); i++) {
      for (int j = 0; j < s2.length(); j++) {
        // important!
        if (i == 0 || j == 0) {
          if (s1.charAt(i) == s2.charAt(j)) {
            f[i][j] = 1;
          } else {
            if (i > 0) {
              f[i][j] = f[i - 1][j];
            }
            if (j > 0) {
              f[i][j] = f[i][j - 1];
            }
          }
        } else {
          if (s1.charAt(i) == s2.charAt(j)) {
            f[i][j] = getMax(f[i - 1][j], f[i][j - 1], f[i - 1][j - 1] + 1);
          } else {
            f[i][j] = getMax(f[i - 1][j], f[i][j - 1], f[i - 1][j - 1]);
          }
        }
      }
    }

    System.out.println(f[s1.length() - 1][s2.length() - 1]);
  }
Esempio n. 10
0
  public static void main(String[] args) {
    Scanner in = new Scanner(System.in);
    String s = in.next();

    int l = s.length();
    Double sqrl = Math.sqrt(l);
    Double low = Math.floor(sqrl);
    Double high = Math.ceil(sqrl);
    int r = 0;
    int c = 0;

    if (low == high) {
      r = low.intValue();
      c = low.intValue();
    } else if (low * high >= l) {
      r = low.intValue();
      c = high.intValue();
    } else {
      r = high.intValue();
      c = high.intValue();
    }

    //        System.out.println("Row: " + r);
    //        System.out.println("Col: " + c);

    StringBuilder sb = new StringBuilder();
    char en[] = s.toCharArray();
    for (int i = 0; i < c; i++) {
      for (int j = 0; j < r; j++) {
        if (j * c + i < l) {
          sb.append(en[j * c + i]);
        }
      }
      sb.append(" ");
    }

    System.out.println(sb.toString());
  }
Esempio n. 11
0
  public static void main(String[] args) {
    /* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution. */
    Scanner sc = new Scanner(System.in);
    int t = sc.nextInt();
    while (t != 0) {
      int R, C, r, c;
      R = sc.nextInt();
      C = sc.nextInt();
      char grid[][] = new char[R][C];

      for (int i = 0; i < R; i++) {
        String l = sc.next();
        for (int j = 0; j < C; j++) {
          grid[i][j] = l.charAt(j);
        }
      }

      r = sc.nextInt();
      c = sc.nextInt();
      char pattern[][] = new char[r][c];
      for (int i = 0; i < r; i++) {
        String l = sc.next();
        for (int j = 0; j < c; j++) {
          pattern[i][j] = l.charAt(j);
        }
      }
      int i = 0;
      String g = new String(grid[i]);
      String p = new String(pattern[i]);
      int present = 0;
      while (i < R) {
        int cc = g.indexOf(p);
        int flag = 0;
        if (cc != -1) {
          for (int k = 1; k < r; k++) {
            g = new String(grid[i + k]);
            p = new String(pattern[k]);
            int x = g.indexOf(p, cc);
            if (x != cc) {
              flag = 1;
              break;
            }
          }
          if (flag == 1) {
            p = new String(pattern[0]);
          } else {
            System.out.println("YES");
            present = 1;
            break;
          }
        }

        i++;
        if (i > R - r) {
          break;
        }
        g = new String(grid[i]);
      }
      if (present == 0) {
        System.out.println("NO");
      }

      t--;
    }
  }
  public BankMessage makeMessage() {

    Scanner stdIn = new Scanner(System.in);
    int userInput;

    int[] opcodes = {CREATE, DEPOSIT, WITHDRAW, GETBALANCE, CLOSE};

    do {
      userInput = stdIn.nextInt();
    } while (!(userInput >= 1 && userInput <= 5));

    int opcode = opcodes[userInput - 1];
    int[] parameters = new int[2];

    // create a pattern only accepting positive numbers with at most 2 decimal places
    Pattern dollar =
        Pattern.compile(
            "^\\$?([1-9]{1}[0-9]{0,2}(\\,[0-9]{3})*(\\.[0-9]{0,2})?|[1-9]{1}[0-9]{0,}(\\.[0-9]{0,2})?|0(\\.[0-9]{0,2})?|(\\.[0-9]{1,2})?)$");
    String input = null;

    // populate parameters list
    switch (opcode) {
      case CREATE:
        do {
          System.out.println("How much for initial deposit?");
          input = stdIn.next();
        } while ((dollar.matcher(input).matches()) == false);
        parameters[0] = (int) (Double.parseDouble(input) * 100);

        break;

      case DEPOSIT:
        System.out.println("Which account?");
        parameters[0] = stdIn.nextInt();

        do {
          System.out.println("How much to deposit?");
          input = stdIn.next();
        } while ((dollar.matcher(input).matches()) == false);
        parameters[1] = (int) (Double.parseDouble(input) * 100);
        break;

      case WITHDRAW:
        System.out.println("Which account?");
        parameters[0] = stdIn.nextInt();

        do {
          System.out.println("How much to withdraw?");
          input = stdIn.next();
        } while ((dollar.matcher(input).matches()) == false);
        parameters[1] = (int) (Double.parseDouble(input) * 100);
        break;

      case GETBALANCE:
        System.out.println("Which account?");
        parameters[0] = stdIn.nextInt();
        break;

      case CLOSE:
        System.out.println("Which account?");
        parameters[0] = stdIn.nextInt();
        break;

      default:
        System.out.println("Invalid opcode. System failure.");
        System.exit(-1);
    }

    BankMessage output = buildMessage(opcode, parameters);
    return output;
  }