public void solve() {
   Scanner s = new Scanner(System.in);
   while (s.hasNext()) {
     int n = s.nextInt();
     System.out.println(ci(n + 1));
   }
 }
示例#2
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;
  }
示例#3
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);
    }
  }
示例#4
0
文件: uva575.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.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);
    }
  }
示例#5
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();
        }
      }
    }
  }
  /**
   * 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();
  }
示例#7
0
文件: edge.java 项目: mo0o/Sociograph
  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;
  }