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);
 }
 public void solve() {
   Scanner s = new Scanner(System.in);
   while (s.hasNext()) {
     int n = s.nextInt();
     System.out.println(ci(n + 1));
   }
 }
Esempio n. 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);
  }
Esempio n. 4
0
  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);
    }
  }
Esempio n. 5
0
  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);
    }
  }
Esempio n. 6
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();
   }
 }
Esempio n. 7
0
 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));
   }
 }
Esempio n. 8
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);
  }
Esempio n. 9
0
  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]));
    }
  }
Esempio n. 10
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. 11
0
  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);
    }
  }
Esempio n. 12
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));

    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++;
    }
  }
Esempio n. 13
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));

    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);
    }
  }
Esempio n. 14
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.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());
    }
  }
Esempio n. 15
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");
     }
Esempio n. 16
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();
        }
      }
    }
  }
Esempio n. 17
0
  public void scanFile(String filename) {
    int i = 0;
    String line = null;
    try {

      File filescan = new File(filename);
      ;

      FileReader f = new FileReader(filescan);

      BufferedReader fileReader = new BufferedReader(f);

      while ((line = fileReader.readLine()) != null) {
        if (i == 0) // read dimensions and create map
        {
          String[] temp = line.split(" ");
          row = Integer.parseInt(temp[0]);
          col = Integer.parseInt(temp[1]);
          map = new char[row][col];
          line = fileReader.readLine();
        }

        Scanner scan = new Scanner(line);
        String temp = scan.next();
        char[] charline = temp.toCharArray();

        // System.out.println(charline);
        map[i] = charline;
        i++;
      }

    } catch (FileNotFoundException e) {
      System.out.println("Error opening file!");
    } catch (IOException ex) {
      System.out.println("Error reading file!");
    }
  }
Esempio n. 18
0
  public static LinkedList<edge> importer(MatlabProxy proxy)
      throws IOException, MatlabConnectionException, MatlabInvocationException {

    Scanner sFile;
    edge entry;
    LinkedList<edge> tie = new LinkedList<edge>();
    Long k, p;

    try {
      sFile =
          new Scanner(new File("/Users/richarddavies/NetBeansProjects/typ_MatlabGraph/edges.dat"));

      System.out.println(sFile.nextLine());

      while (sFile.hasNext()) {

        String edge = sFile.nextLine();
        // System.out.println(edge);

        Scanner edgeScan = new Scanner(edge);
        edgeScan.useDelimiter(",");

        while (edgeScan.hasNext()) {

          k = edgeScan.nextLong();
          System.out.print(k + " ");

          String ident_k = String.valueOf(k);
          String rot_Id_k = rot13.encrypt(ident_k);
          Long rot_k = Long.parseLong(rot_Id_k);

          p = edgeScan.nextLong();
          System.out.print(p);

          String ident_p = String.valueOf(p);
          String rot_Id_p = rot13.encrypt(ident_p);
          Long rot_p = Long.parseLong(rot_Id_p);

          // System.out.println(rot_k+" : "+rot_p);
          entry = new edge(k, p);

          int n = search.search(k);
          int m = search.search(p);
          System.out.print(
              " : "
                  + Typ_MatlabGraph.people.get(n).idProf
                  + " "
                  + Typ_MatlabGraph.people.get(m).idProf);
          System.out.println("");
          n++;
          m++;

          proxy.eval("adjMatrix(" + n + "," + m + ") = 1");

          tie.add(entry);
        }
      }

    } catch (IOException ex) {

      System.out.println("(No System File profile.txt)" + ex);
    }

    return tie;
  }
Esempio n. 19
0
  public Stock(String StockSymbol) throws IOException {

    symbol = StockSymbol;

    String date = "2014-04-13";

    String url =
        "https://query.yahooapis.com/v1/public/yql?q=SELECT%20*%20FROM%20yql.query.multi%20WHERE%20queries%3D%27%0A%20%20%20%20"
            + "SELECT%20*%20FROM%20csv%20WHERE%20url%3D%22http%3A%2F%2Fdownload.finance.yahoo.com%2Fd%2Fquotes.csv%3Fs%3D"
            + symbol
            + "%26f%3Dl1ohgvc6a2p2m4m3%26e%3D.csv%22%0A%20%20%20%20AND%20"
            + "columns%3D%22lastPrice%2Copen%2Chigh%2Clow%2Cvolumen%2Cchange%2CavgVolumen%2CchangePer%2CMA200%2CMA50%22%3B%0A%20%20%20%20"
            + "SELECT%20Symbol%2CDate%2CClose%20FROM%20yahoo.finance.historicaldata%20where%20symbol%20%3D%20%22"
            + symbol
            + "%22%20and%20startDate%20%3D%20%22"
            + date
            + "%22%20and%20endDate%20%3D%20%22now%22%0A%27%3B&env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys";
    try {
      URL pageLocation = new URL(url);

      Scanner input = new Scanner(pageLocation.openStream());
      String webData = input.nextLine() + "\n";

      while (input.hasNextLine()) {
        webData += input.nextLine() + "\n";
      }
    } catch (MalformedURLException e) {
      System.out.printf("Error");
    }

    int startIndex, endIndex; // Here we initialize the two int variables to be used to get the data

    // Here we grab the lastest price from the xml
    startIndex = webData.indexOf("<lastPrice>");
    endIndex = webData.indexOf("</lastPrice>", startIndex);
    lastPrice = Float.parseFloat(webData.substring(startIndex + 11, endIndex));

    if (lastPrice == 0.00) {
      /* Udvikle error da aktien ikke findes */
    }

    // Here we grab the open price from the xml
    startIndex = webData.indexOf("<open>");
    endIndex = webData.indexOf("</open>", startIndex);
    open = Float.parseFloat(webData.substring(startIndex + 6, endIndex));

    // Here we grab the High price of the day from the xml
    startIndex = webData.indexOf("<high>");
    endIndex = webData.indexOf("</high>", startIndex);
    high = Float.parseFloat(webData.substring(startIndex + 6, endIndex));

    // Here we grab the Low price of the day from the xml
    startIndex = webData.indexOf("<low>");
    endIndex = webData.indexOf("</low>", startIndex);
    low = Float.parseFloat(webData.substring(startIndex + 5, endIndex));

    // Here we grab the volume
    startIndex = webData.indexOf("<volumen>");
    endIndex = webData.indexOf("</volumen>", startIndex);
    volumen = Integer.parseInt(webData.substring(startIndex + 9, endIndex));

    // Here we grab the average volume
    startIndex = webData.indexOf("<avgVolumen>");
    endIndex = webData.indexOf("</avgVolumen>", startIndex);
    avgVolumen = Integer.parseInt(webData.substring(startIndex + 12, endIndex));

    // Here we grab the change of price
    startIndex = webData.indexOf("<change>");
    endIndex = webData.indexOf("</change>", startIndex);
    change = Float.parseFloat(webData.substring(startIndex + 8, endIndex));

    // Here we grab the change of price in percent
    startIndex = webData.indexOf("<changePer>");
    endIndex = webData.indexOf("</changePer>", startIndex);
    changeInPer = Float.parseFloat(webData.substring(startIndex + 11, endIndex - 1));

    // Here we grab the 200 Moving Average
    startIndex = webData.indexOf("<MA200>");
    endIndex = webData.indexOf("</MA200>", startIndex);
    MA200 = Float.parseFloat(webData.substring(startIndex + 7, endIndex));

    // Here we grab the 200 Moving Average
    startIndex = webData.indexOf("<MA50>");
    endIndex = webData.indexOf("</MA50>", startIndex);
    MA50 = Float.parseFloat(webData.substring(startIndex + 6, endIndex));

    rsi = rsiCalculate(pastPrices);

    emas = emaCalculate(pastPrices);
  }
  /**
   * 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();
  }
Esempio n. 21
0
  public static LinkedList<profile> importer() throws IOException {

    LinkedList<profile> people = new LinkedList<profile>();
    Scanner sFile;
    profile entry;

    try {
      sFile =
          new Scanner(new File("/Users/richarddavies/NetBeansProjects/typ_MatlabGraph/users.dat"));
      sFile.nextLine();
      while (sFile.hasNext()) {

        String profile = sFile.nextLine();
        // System.out.println(profile);

        Scanner profScan = new Scanner(profile);
        profScan.useDelimiter(",");

        while (profScan.hasNext()) {

          Long id = profScan.nextLong();
          String ident = String.valueOf(id);
          String rot_Id = rot13.encrypt(ident);
          Long rot_IntId = Long.parseLong(rot_Id);

          String fname = profScan.next();
          String rot_Name = rot13.encrypt(fname);
          // String sname = profScan.next();
          // int age = profScan.nextInt();
          String gender = profScan.next();
          String nat = profScan.next();

          entry = new profile(id, fname, gender, nat);
          // System.out.println("id: "+id+" name: "+fname+" gender: "+gender+" nationality: "+nat);
          // System.out.println("id: "+rot_IntId+" name: "+rot_Name+" gender: "+gender+"
          // nationality: "+nat);
          people.add(entry);
        }
      }

    } catch (IOException ex) {
      // return people;

      System.out.println("(No System File profile.txt)" + ex);
    }
    return people;
  }
Esempio n. 22
0
 public void select() {
   Scanner keyboard = new Scanner(System.in);
   String user = keyboard.nextLine();
   user.toLowerCase();
   set_user(user);
 }
Esempio n. 23
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);
    }
  }