25/07/2014

11687 - Digits - JAVA

package org.goro.uva.m;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Digits {

 public static void main(String[] args) throws IOException {
  

  Reader.init(System.in);
  StringBuilder sb = new StringBuilder();

  String line = Reader.next();
  while (!line.equals("END")) {
   int lenght = line.length();

   if (line.equals("1")) {
    sb.append(1);
   } else if (lenght < 2) {
    sb.append(2);
   } else if (lenght < 10) {
    sb.append(3);
   } else {
    sb.append(4);
   }

   line = Reader.next();
   if (!line.equals("END")) {
    sb.append("\n");
   }
  }
  System.out.println(sb);
 }

}

/** Class for buffered reading int and double values */
/** http://www.cpe.ku.ac.th/~jim/java-io.html */
class Reader {
 static BufferedReader reader;
 static StringTokenizer tokenizer;

 /** call this method to initialize reader for InputStream */
 static void init(InputStream input) {
  reader = new BufferedReader(new InputStreamReader(input));
  tokenizer = new StringTokenizer("");
 }

 /** get next word */
 static String next() throws IOException {
  while (!tokenizer.hasMoreTokens()) {
   tokenizer = new StringTokenizer(reader.readLine());
  }
  return tokenizer.nextToken();
 }

 static int nextInt() throws IOException {
  return Integer.parseInt(next());
 }

 static double nextDouble() throws IOException {
  return Double.parseDouble(next());
 }
}

1 comment:

  1. Kapelushinho maybe we can grab a bottle of beer together?

    ReplyDelete