コード例 #1
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[][] numArray = new String[6][];
    int largestSum = 0;
    for (int i = 0; i < 6; i++) {
      numArray[i] = sc.nextLine().split(" ");
    }

    for (int i = 0; i <= 3; i++) {
      for (int j = 0; j <= 3; j++) {
        int sum =
            Integer.parseInt(numArray[i][j])
                + Integer.parseInt(numArray[i][j + 1])
                + Integer.parseInt(numArray[i][j + 2])
                + Integer.parseInt(numArray[i + 1][j + 1])
                + Integer.parseInt(numArray[i + 2][j])
                + Integer.parseInt(numArray[i + 2][j + 1])
                + Integer.parseInt(numArray[i + 2][j + 2]);
        // System.out.println(sum);
        if (i == 0 && j == 0) {
          largestSum = sum;
        } else {
          if (sum > largestSum) {
            largestSum = sum;
          }
        }
      }
    }

    System.out.println(largestSum);
  }
コード例 #2
0
  public static void main(String[] args) {
    Scanner in = new Scanner(System.in);
    int arr[][] = new int[6][6];
    int max = -10000; // lowest possible value is -9*6=-54
    int sum;
    for (int arr_i = 0; arr_i < 6; arr_i++) {
      for (int arr_j = 0; arr_j < 6; arr_j++) {
        arr[arr_i][arr_j] = in.nextInt();
      }
    }

    for (int i = 0; i < 4; i++) {
      for (int j = 0; j < 4; j++) {
        sum =
            arr[i][j]
                + arr[i][j + 1]
                + arr[i][j + 2]
                + arr[i + 1][j + 1]
                + arr[i + 2][j]
                + arr[i + 2][j + 1]
                + arr[i + 2][j + 2];
        max = Math.max(sum, max);
      }
    }
    System.out.println(max);
  }
コード例 #3
0
  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();
  }
コード例 #4
0
ファイル: Solution1.java プロジェクト: leviathan88/30DaysHR
  public static void main(String[] args) {
    Scanner in = new Scanner(System.in);
    int arr[][] = new int[6][6];
    for (int i = 0; i < 6; i++) {
      for (int j = 0; j < 6; j++) {
        arr[i][j] = in.nextInt();
      }
    }

    List sum = new ArrayList();
    for (int i = 1; i < 5; i++) {
      for (int j = 1; j < 5; j++) {
        int temp =
            arr[i][j]
                + arr[i - 1][j - 1]
                + arr[i - 1][j]
                + arr[i - 1][j + 1]
                + arr[i + 1][j - 1]
                + arr[i + 1][j]
                + arr[i + 1][j + 1];
        sum.add(temp);
      }
    }

    System.out.println(Collections.max(sum));
  }
コード例 #5
0
 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]);
   }
 }
コード例 #6
0
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int T = sc.nextInt();

    long d3 = 3, d5 = 5, d15 = 15;
    long n3 = 0, n5 = 0, n15 = 0;
    if ((1 <= T) && (T <= 100000)) {
      for (int j = 0; j < T; j++) {
        long sum3 = 0, sum5 = 0, sum15 = 0, sum = 0;
        long l3, l5, l15 = 0;

        int N = sc.nextInt();
        if ((1 <= N) && (N <= 1000000000)) {
          N = N - 1;
          l3 = N % 3;
          l3 = N - l3;
          n3 = (l3 - 3) / 3 + 1;
          sum3 = (3 * ((n3) + 1) * (n3)) / 2;

          l5 = N % 5;
          l5 = N - l5;
          n5 = (l5 - 5) / 5 + 1;
          sum5 = (5 * ((n5) + 1) * (n5)) / 2;

          l15 = N % 15;
          l15 = N - l15;
          n15 = (l15 - 15) / 15 + 1;
          sum15 = (15 * ((n15) + 1) * (n15)) / 2;

          sum = sum3 + sum5 - sum15;
          System.out.println(sum);
        }
      }
    }
  }
コード例 #7
0
 private static void displayPhoneBooks(ArrayList<String> phoneBooks)
     throws IOException, ParseException {
   if (phoneBooks.size() == 0) {
     System.out.println("\nNO PHONEBOOK AVAILABLE.CREATE A NEW PHONEBOOK.\n");
     return;
   } else {
     System.out.println("FOLLOWING ARE THE AVAILABLE PHONEBOOKS.");
     System.out.println("----------------------------------------\n");
     Scanner sc = new Scanner(System.in);
     for (int i = 0; i < phoneBooks.size(); i++) {
       String s = phoneBooks.get(i);
       System.out.println(s + "\t->PRESS " + (i + 1) + " LOAD THIS.");
     }
     System.out.println("TO GO BACK TO THE PREVIOUS MENU->PRESS " + (phoneBooks.size() + 1));
     int ch = 0;
     while (ch < 1 || ch > (phoneBooks.size() + 1)) {
       while (!sc.hasNextInt()) {
         System.out.println("\nONLY NUMBERS LISTED ABOVE SHOULD BE ENTERED..RETRY..");
         sc.nextLine();
       }
       ch = sc.nextInt();
       if (ch < 1 || ch > phoneBooks.size())
         System.out.println("\nONLY NUMBERS LISTED ABOVE SHOULD BE ENTERED..RETRY..");
     }
     if (ch == (phoneBooks.size() + 1)) return;
     contactBookOperations(phoneBooks.get(ch - 1) + ".txt");
   }
 }
コード例 #8
0
ファイル: SwapNodes.java プロジェクト: ryumer/hackerrank
  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 in = new Scanner(System.in);

    int N = in.nextInt();

    Node[] nodes = new Node[N];

    for (int i = 0; i < N; i++) {
      nodes[i] = new Node(i + 1);
    }

    for (int i = 0; i < N; i++) {
      int a = in.nextInt();
      int b = in.nextInt();

      Node n = nodes[i];

      if (a != -1) n.left = nodes[a - 1];
      if (b != -1) n.right = nodes[b - 1];
    }

    int T = in.nextInt();

    for (int i = 0; i < T; i++) {
      int K = in.nextInt();

      swap(nodes[0], K, 1);

      Inorder(nodes[0]);
      System.out.println("");
    }
  }
コード例 #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. */

    try {

      Scanner sc = new Scanner(new File("/home/santosh/Desktop/testData"));

      int testCases = sc.nextInt();
      int i = 0;
      ArrayList<ArrayList<Integer>> inputArraysList = new ArrayList<ArrayList<Integer>>();
      ArrayList<Integer> list;
      while (i++ < testCases) {

        int n = sc.nextInt();
        int k = 0;
        list = new ArrayList<Integer>();
        while (k < n) {
          list.add(sc.nextInt());
          k++;
        }
        inputArraysList.add(list);
      }

      // System.out.println(inputArraysList.size());
      for (ArrayList<Integer> arr : inputArraysList) {
        countPairs(arr.toArray(new Integer[arr.size()]));
      }

    } catch (Exception e) {

    }
  }
コード例 #10
0
ファイル: 433.java プロジェクト: jmankhan/ACM
  public void solve() throws Exception {
    int n = in.nextInt();
    int[] a = new int[n];
    int sum = 0;

    for (int i = 0; i < n; i++) {
      a[i] = in.nextInt();
      sum += a[i];
    }

    sum /= 2;

    boolean[] dp = new boolean[sum + 1];
    dp[0] = true;

    for (int tmp : a) {
      for (int i = sum; i >= tmp; i--) {
        if (dp[i - tmp]) {
          dp[i] = true;
        }
      }
    }

    String ans = dp[sum] ? "YES" : "NO";
    out.println(ans);
  }
コード例 #11
0
 public void init() {
   Scanner scan = new Scanner(System.in);
   count = scan.nextInt();
   x0 = scan.nextLong();
   y0 = scan.nextLong();
   int result = 0;
   boolean special = false;
   for (int i = 0; i < count; i++) {
     long tempx = scan.nextLong();
     long tempy = scan.nextLong();
     if (tempx == x0 && tempy == y0) {
       special = true;
       continue;
     }
     boolean isDuplicate = false;
     for (int j = 0; j < result; j++) {
       long x1 = xList.get(j);
       long y1 = yList.get(j);
       if ((x1 - x0) * (tempy - y0) == (y1 - y0) * (tempx - x0)) {
         isDuplicate = true;
         break;
       }
     }
     if (!isDuplicate) {
       xList.add(tempx);
       yList.add(tempy);
       result++;
     }
   }
   if (special && result == 0) result = 1;
   System.out.println(result);
   scan.close();
 }
コード例 #12
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 in = new Scanner(System.in);
   int cases = in.nextInt();
   for (int i = 0; i < cases; i++) {
     System.out.println(digits(in.nextInt()));
   }
 }
コード例 #13
0
 public static void main(String[] args) {
   Scanner in = new Scanner(System.in);
   int t = in.nextInt();
   for (int a0 = 0; a0 < t; a0++) {
     int n = in.nextInt();
     int treeHeight = getHeightOfTree(n);
     System.out.println(treeHeight);
   }
 }
コード例 #14
0
ファイル: JavaBigInt.java プロジェクト: kyuelin/Jobs2014
  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 scan = new Scanner(System.in);
    BigInteger bigInteger1 = scan.nextBigInteger();
    BigInteger bigInteger2 = scan.nextBigInteger();

    System.out.println(bigInteger1.add(bigInteger2));
    System.out.println(bigInteger1.multiply(bigInteger2));
  }
コード例 #15
0
ファイル: uva706.java プロジェクト: de-yu/uva
  public static void main(String[] args) throws IOException {
    Scanner scanner = new Scanner(new BufferedInputStream(System.in));

    int num[][] = {
      {0, 2, 3, 5, 6, 7, 8, 9},
      {2, 3, 4, 5, 6, 8, 9},
      {0, 2, 3, 5, 6, 8, 9},
      {0, 4, 5, 6, 8, 9},
      {0, 1, 2, 3, 4, 7, 8, 9},
      {0, 2, 6, 8},
      {0, 1, 3, 4, 5, 6, 7, 8, 9}
    };

    while (scanner.hasNextInt()) {
      int a = scanner.nextInt();
      String b = scanner.next();
      if (a == 0) break;
      String data[][] = new String[5 + (a - 1) * 2][(3 + (a - 1)) * b.length()];

      for (int i = 0; i < 5 + (a - 1) * 2; i++)
        for (int j = 0; j < (3 + (a - 1)) * b.length(); j++) data[i][j] = " ";

      for (int i = 0; i < b.length(); i++) {
        for (int j = 0; j < 3; j++) {
          for (int k = 0; k < num[j].length; k++) {
            if ((int) b.charAt(i) - 48 == num[j][k]) {
              for (int h = 0; h < a; h++) data[(a + 1) * j][1 + i * (a + 2) + h] = "-";
            }
          }
        }
        for (int j = 3; j < 5; j++) {
          for (int k = 0; k < num[j].length; k++) {
            if ((int) b.charAt(i) - 48 == num[j][k]) {
              for (int h = 0; h < a; h++) data[1 + h][(j - 3) * (a + 1) + (i * (a + 2))] = "|";
            }
          }
        }
        for (int j = 5; j < 7; j++) {
          for (int k = 0; k < num[j].length; k++) {
            if ((int) b.charAt(i) - 48 == num[j][k]) {
              for (int h = 0; h < a; h++) data[a + 2 + h][(j - 5) * (a + 1) + (i * (a + 2))] = "|";
            }
          }
        }
      }
      StringBuffer sb = new StringBuffer("");
      for (int i = 0; i < 5 + (a - 1) * 2; i++) {
        for (int j = 0; j < (3 + (a - 1)) * b.length(); j++) {
          if ((j - (a + 1)) % (a + 2) == 0 && (j + 1) != (3 + (a - 1)) * b.length())
            sb.append(data[i][j] + " ");
          else sb.append(data[i][j]);
        }
        sb.append("\n");
      }
      System.out.println(sb);
    }
  }
コード例 #16
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);
 }
コード例 #17
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 in = new Scanner(System.in);
   int numberOfTestCases = in.nextInt();
   for (int i = 0; i < numberOfTestCases; i++) {
     int n = in.nextInt();
     System.out.println((n * (n - 1)) / 2);
   }
 }
コード例 #18
0
ファイル: uva619.java プロジェクト: de-yu/uva
  public static void main(String[] args) throws IOException {
    Scanner scanner = new Scanner(new BufferedInputStream(System.in));

    while (scanner.hasNext()) {
      String str = scanner.next();
      if (str.equals("*")) break;
      if ((int) str.charAt(0) < 97) num(str);
      else abcd(str);
    }
  }
コード例 #19
0
ファイル: pathToPrincess.java プロジェクト: spl0i7/HackerRank
 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);
 }
コード例 #20
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 mapSize = Integer.parseInt(sc.nextLine());
   char[][] map = new char[mapSize][];
   for (int i = 0; i < mapSize; i++) {
     String numbersString = sc.nextLine();
     map[i] = numbersString.toCharArray();
   }
   printMapWithCavities(map, mapSize);
 }
コード例 #21
0
 public static void main(String[] args) {
   Scanner sc = new Scanner(System.in);
   int k = sc.nextInt();
   while (k > 0) {
     int a = sc.nextInt();
     int b = sc.nextInt();
     int n = sc.nextInt();
     printer(a, b, n);
     k--;
   }
 }
コード例 #22
0
ファイル: Day3.java プロジェクト: aarti27/Hackerrank
  public static void main(String[] args) {

    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    String ans = "";
    if (n % 2 == 1) ans = "Weird";
    else if (n >= 2 && n <= 5) ans = "Not Weird";
    else if (n <= 20) ans = "Weird";
    else ans = "Not Weird";
    System.out.println(ans);
  }
コード例 #23
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 scan = new Scanner(System.in);
   long T = scan.nextLong();
   for (long i = 0; i < T; i++) {
     long N = scan.nextLong();
     long diff = 0;
     diff = wholeSum(N) - indiSum(N);
     System.out.println(diff);
   }
 }
 public static void main(String[] args) {
   Scanner sc = new Scanner(System.in);
   int a = sc.nextInt();
   if (a == 2) {
     System.out.println("Bob wins, by winning 2 game(s) and tying 1 game(s)");
     System.out.println("Alice and Bob tie, each winning 0 game(s) and tying 1 game(s)");
   } else {
     System.out.println("Alice wins, by winning 2 game(s) and tying 1 game(s)");
     System.out.println("Alice and Bob tie, each winning 0 game(s) and tying 1 game(s)");
   }
 }
コード例 #25
0
ファイル: AVeryBigSum.java プロジェクト: deepmehtait/code
  public static void main(String[] args) {
    BigInteger sum = BigInteger.ZERO;
    Scanner in = new Scanner(System.in);
    int n = in.nextInt();
    int arr[] = new int[n];
    for (int arr_i = 0; arr_i < n; arr_i++) {
      arr[arr_i] = in.nextInt();

      sum = sum.add(BigInteger.valueOf(arr[arr_i]));
    }
    System.out.println(sum);
  }
コード例 #26
0
  public static void main(String[] args) {
    Scanner in = new Scanner(System.in);
    int N = in.nextInt();
    int arr[] = new int[N];
    for (int i = 0; i < N; i++) {
      arr[i] = in.nextInt();
    }

    for (int i = N - 1; i >= 0; i--) {
      System.out.print(arr[i] + " ");
    }
  }
コード例 #27
0
  public static void main(String[] args) {
    Scanner in = new Scanner(System.in);
    int T = Integer.parseInt(in.nextLine());

    for (int a = 0; a < T; a++) {

      String PAN = in.nextLine();
      System.out.println(isValidPAN(PAN));
    }

    in.close();
  }
コード例 #28
0
  public static Matrix scanMatrix() { // 输入矩阵
    int i, j;
    Matrix matrix = new Matrix();
    Scanner scanner = new Scanner(System.in);

    matrix.setLine(scanner.nextInt());
    matrix.setRow(scanner.nextInt());
    matrix.setAccuracy(scanner.nextDouble());
    for (i = 0; i < matrix.getLine(); i++) {
      for (j = 0; j < matrix.getRow(); j++) matrix.setElement(i, j, scanner.nextDouble());
    }
    return matrix;
  }
コード例 #29
0
ファイル: uva516.java プロジェクト: de-yu/uva
 public static void main(String[] args) throws IOException {
   Scanner scanner = new Scanner(new BufferedInputStream(System.in));
   while (scanner.hasNextLine()) {
     String str = scanner.nextLine();
     if (str.equals("0")) break;
     String s[] = str.split(" ");
     int sum = 1;
     for (int i = 0; i < s.length; i += 2)
       sum = sum * (int) Math.pow(Integer.parseInt(s[i]), Integer.parseInt(s[i + 1]));
     Factorization f = new Factorization();
     System.out.println(f.answer(sum - 1));
   }
 }
コード例 #30
0
  public static void main(String[] args) {
    long start = System.currentTimeMillis();
    Scanner input = new Scanner(System.in);
    int numberOfTestCases = input.nextInt();
    ArrayList<Integer> order = new ArrayList<Integer>(numberOfTestCases);
    int previousKey = -1;
    int previousValue = 0;
    int cycleNumber = 0;

    Map<Integer, Integer> testCases = new TreeMap<Integer, Integer>();

    for (int i = 0; i < numberOfTestCases; i++) {
      int numberOfCycles = input.nextInt();
      testCases.put(numberOfCycles, 1);
      order.add(numberOfCycles);
    }

    for (Map.Entry<Integer, Integer> entry : testCases.entrySet()) {
      int numberOfCycles;
      int initialHeight;

      if (previousKey == -1) {
        numberOfCycles = entry.getKey();
        initialHeight = entry.getValue();
      } else {
        numberOfCycles = entry.getKey() - previousKey;
        initialHeight = previousValue;
      }

      for (int i = 0; i < numberOfCycles; i++) {
        if (cycleNumber % 2 == 0) {
          initialHeight *= 2;
        } else {
          initialHeight += 1;
        }
        cycleNumber++;
      }

      entry.setValue(initialHeight);
      previousKey = entry.getKey();
      previousValue = initialHeight;
    }

    for (Integer element : order) {
      System.out.println(testCases.get(element));
    }

    long elapsed = System.currentTimeMillis() - start;
    System.out.println("time: " + elapsed);
  }