コード例 #1
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);
    }
  }
コード例 #2
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);
    }
  }
コード例 #3
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++;
    }
  }
コード例 #4
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());
    }
  }
コード例 #5
0
  /**
   * 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();
  }