public static void main(String[] args) {
   Scanner sc = new Scanner(System.in);
   int M = sc.nextInt();
   int N = sc.nextInt();
   int a[][] = new int[M + 1][N + 1];
   int dp[][] = new int[M + 1][N + 1];
   for (int i = 1; i <= M; i++) {
     for (int j = 1; j <= N; j++) {
       a[i][j] = sc.nextInt();
       if (a[i][j] == 0) a[i][j] = -9999999;
     }
   }
   for (int i = 1; i <= M; i++) {
     for (int j = 1; j <= N; j++) {
       dp[i][j] = dp[i - 1][j] + dp[i][j - 1] - dp[i - 1][j - 1] + a[i][j];
     }
   }
   int max = -100000000;
   for (int i = 1; i <= M; i++) {
     for (int j = 1; j <= N; j++) {
       for (int k = 1; k <= M; k++) {
         if (i + k > M) break;
         else if (j + k > N) break;
         int temp = dp[i + k][j + k] - dp[i - 1][j + k] - dp[i + k][j - 1] + dp[i - 1][j - 1];
         max = Math.max(max, temp);
       }
     }
   }
   System.out.println(max);
 }
示例#2
0
  public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);
    System.out.print("Length of logs array:");
    int length = scanner.nextInt();

    System.out.print("The array:");
    int[] logs = new int[length];
    for (int i = 0; i < length; i++) {
      logs[i] = scanner.nextInt();
    }

    cut(logs);
  }
示例#3
0
  public static void main(String[] args) {
    // TODO Auto-generated method stub

    Scanner in = new Scanner(System.in);
    Hashtable numbers = new Hashtable();

    N = in.nextInt();
    K = in.nextLong();

    long[] arr = new long[N];
    for (int i = 0; i < N; i++) {
      arr[i] = in.nextLong();
      numbers.put(Long.toString(arr[i]), arr[i]);
    }

    result = 0;

    for (int i = 0; i < N; i++) {
      long tmp = 0, tmp2 = 0;
      tmp = arr[i] + K;
      try {
        tmp2 = (Long) numbers.get(Long.toString(tmp));
        result++;
      } catch (Exception ex) {

      }
    }

    System.out.println(result);
  }
 public void solve() {
   Scanner s = new Scanner(System.in);
   while (s.hasNext()) {
     int n = s.nextInt();
     System.out.println(ci(n + 1));
   }
 }
示例#5
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);
    }
  }
示例#6
0
 public static void main(String arg[])
        {
          Scanner d=new Scanner(System.in);
           int n=d.nextInt();
           int count=0;
           int arr[]=new int[n+1];
           for(int i=0;i<n;i++)
           arr[i]=d.nextInt();
           for(int i=0;i<n-1;i++)
            {
                  for(int j=i+1;j<n;j++)
                  {
                       if(a[i)>a[j])
                       count++;
                  }
            }
            if(count>0)
            System.out.println("Values not sorted");
            else
            System.out.println("Sorted");
     }
示例#7
0
 public static void main(String args[]) {
   int T;
   String s;
   Scanner in = new Scanner(System.in);
   T = in.nextInt();
   for (int i = 0; i < T; i++) {
     s = in.next();
     // toReverse(s);
     reverse(s);
     System.out.println();
   }
 }
示例#8
0
文件: Mock5.java 项目: afiqiqmal/Java
  public static void main(String[] args) {
    Scanner scan = new Scanner(System.in);

    String line = System.getProperty("line.separator");
    scan.useDelimiter(line);

    int cases = scan.nextInt();

    for (int x = 0; x < cases; x++) {

      String[] get = scan.next().split(" ");

      System.out.println(Integer.parseInt(get[0]) % Integer.parseInt(get[1]));
    }
  }
示例#9
0
文件: uva11332.java 项目: de-yu/uva
  public static void main(String[] args) throws IOException {
    Scanner scanner = new Scanner(new BufferedInputStream(System.in));

    while (scanner.hasNextInt()) {
      int a = scanner.nextInt();
      if (a == 0) break;
      while (a / 10 != 0) {
        int sum = 0;
        while (a / 10 != 0) {
          sum = sum + a % 10;
          a = a / 10;
        }
        a = a + sum;
      }
      System.out.println(a);
    }
  }
示例#10
0
文件: uva10925.java 项目: de-yu/uva
  public static void main(String[] args) throws IOException {
    Scanner scanner = new Scanner(new BufferedInputStream(System.in));
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

    int n = 1;
    while (scanner.hasNextInt()) {
      int a = scanner.nextInt();
      int b = scanner.nextInt();
      if (a == 0) break;
      BigInteger sum = BigInteger.ZERO;
      BigInteger bb = BigInteger.valueOf(b);
      for (int i = 0; i < a; i++) sum = sum.add(scanner.nextBigInteger());

      System.out.println(
          "Bill #" + n + " costs " + sum + ": each friend should pay " + sum.divide(bb) + "\n");
      n++;
    }
  }
示例#11
0
文件: uva10905.java 项目: de-yu/uva
  public static void main(String[] args) throws IOException {

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

    int num;
    while ((num = scanner.nextInt()) != 0) {
      ArrayList<String> all = new ArrayList<String>();
      for (int i = 0; i < num; i++) {
        all.add(scanner.next());
      }
      Collections.sort(all, comptr);
      StringBuilder sb = new StringBuilder("");
      for (String s : all) {
        sb.append(s);
      }
      System.out.println(sb);
    }
  }
示例#12
0
文件: uva10219.java 项目: de-yu/uva
  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.hasNextInt()) {
      int n = scanner.nextInt();
      int k = scanner.nextInt();

      BigInteger sum = BigInteger.ONE;

      for (int i = n; i > n - k; i--) {
        sum = sum.multiply(BigInteger.valueOf(i));
      }
      for (int i = 2; i <= k; i++) {
        sum = sum.divide(BigInteger.valueOf(i));
      }

      System.out.println(sum.toString().length());
    }
  }
示例#13
0
  public static void main(String[] args) throws java.lang.Exception {
    Scanner cin = new Scanner(System.in);
    while (cin.hasNext()) {
      int input = cin.nextInt();
      for (int a = 0; a < input + 1; a++) {
        if (a > 0) {
          String number = cin.nextLine();
          String[] numberArray = number.split(" ");
          int max = 0;

          for (int b = 0; b < numberArray.length; b++) {
            if (Integer.valueOf(numberArray[b]) > max) {
              max = Integer.valueOf(numberArray[b]);
            }
          }

          System.out.println("Case " + a + ": " + max);
        } else {
          String data = cin.nextLine();
        }
      }
    }
  }
示例#14
0
  public static void main(String[] args) {

    //// I shall master R programming
    Scanner s = new Scanner(System.in);
    System.out.println("Enter no of transactions");
    int p = s.nextInt();

    String[] data = new String[p + 1];

    int arr[] = new int[10];

    for (int i = 0; i <= 9; i++) {
      arr[i] = 0;
    }
    // s.delimiter();
    for (int i = 1; i <= p; i++) {
      String gh;
      gh = s.nextLine();
      data[i] = gh;
      char[] buff = new char[10];
      buff = gh.toCharArray();

      for (int j = 0; j < buff.length; j++) {
        int fg = (int) buff[j] - 48;
        arr[fg]++;
      }
    }
    System.out.println("Enter Min_support");
    int minsup = s.nextInt();
    for (int j = 1; j <= 9; j++) {
      if (arr[j] < minsup) {
        arr[j] = -1;
      }
    }

    for (int j = 1; j <= p; j++) {
      char[] buff = new char[10];
      buff = data[j].toCharArray();
      String fin = "";
      for (int h = 0; h < buff.length; h++) {
        int fg = ((int) buff[h]) - 48;
        if (arr[fg] != -1) {
          fin += buff[h];
        }
      }
      data[j] = fin;
      data[j] = sort(data[j], arr);
    }

    /////////// BAsic Stuff done////////////////////////////////////

    ///// FP TREE CONSTRUCTION
    trie tr = new trie();

    for (int j = 1; j <= p; j++) {
      tr.insert(data[j]);
    }
    tr.show(minsup);

    //// FP TREE Construction Done\\\\\\

    //// Now FP TREE Itemset Generation\\\\

    // trie x=new trie();

    int max = 5;
    int[] mark = new int[max + 1];
    int[] yoyo = new int[max + 1];
    for (int i = 0; i <= max; i++) {
      yoyo[i] = i + 1;
      mark[i] = 0;
    }

    int end = (int) Math.pow(2, max);
    for (int i = 1; i < end; i++) {
      mark = bringme(i, max);

      String up = "", down = "";

      for (int j = 0; j < max; j++) {

        if (mark[j] == 1) down += yoyo[j];
      }

      makeCondFP(tr, down, data, p, minsup);
    }
  }
  /**
   * Evaluates a mathematical expression and returns the result
   *
   * @param expression String
   * @return boolean
   */
  public int parse(String expression) throws NoSuchElementException {
    Scanner scan = new Scanner(expression);

    Stack<Integer> stack1 = new Stack<Integer>();

    int num1;
    int num2;

    while (scan.hasNext()) {

      try {

        if (scan.hasNextInt()) {
          int num = scan.nextInt();
          stack1.push(num);
          // System.out.println("push "+ num);
        } else {
          // String str = scan.nextChar();
          // System.out.println("scan "+ scan.next());

          String str = scan.next();

          if (str.equals("+")) {
            num1 = stack1.pop();
            // System.out.println("num1 = "+ num1);
            num2 = stack1.pop();
            // System.out.println("num1 = "+ num2);
            stack1.push(num1 + num2);
          }

          if (str.equals("-")) {
            num1 = stack1.pop();
            num2 = stack1.pop();
            stack1.push(num2 - num1);
          }

          if (str.equals("/")) {
            num1 = stack1.pop();
            num2 = stack1.pop();
            stack1.push(num2 / num1);
          }

          if (str.equals("*")) {
            num1 = stack1.pop();
            num2 = stack1.pop();
            stack1.push(num1 * num2);
          }

          if (str.equals("%")) {
            num1 = stack1.pop();
            num2 = stack1.pop();
            stack1.push(num2 % num1);
          }

          if (str.equals("&")) {
            num1 = stack1.pop();
            num2 = stack1.pop();
            stack1.push(num1 & num2);
          }

          if (str.equals("^")) {
            num1 = stack1.pop();
            num2 = stack1.pop();
            stack1.push(num1 ^ num2);
          }

          if (str.equals("|")) {
            num1 = stack1.pop();
            num2 = stack1.pop();
            stack1.push(num1 | num2);
          }

          if (str.equals("~")) {
            num1 = stack1.pop();

            stack1.push(~num1);
          }
        }

      } catch (NoSuchElementException e) {
        System.out.println("empty stacfgdgdfgk");
      }
    }

    // int result = stack1.pop();

    // System.out.println(result);
    return stack1.pop();
  }