25/07/2014

11683 - Laser Sculpture - 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 LaserSculpture {

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

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

  int height = Reader.nextInt();
  while (height > 0) {
   int lenght = Reader.nextInt();

   int lasers = cut(height, lenght);
   sb.append(lasers);
   
   height = Reader.nextInt();
   if (height > 0) {
    sb.append("\n");
   }
  }
  System.out.println(sb);
 }

 private static int cut(int maxHeight, int lenght) throws IOException {
  int cut = 0;

  int last = maxHeight;
  
  for (int j = 0; j < lenght; j++) {
   int curr = Reader.nextInt();

   if (curr < last) {
    cut += last - curr;
   }

   last = curr;
  }
  return cut;
 }

}

/** 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());
 }
}

2 comments:

  1. Kapelushinho, is it possible to make java cook the meals?

    ReplyDelete
  2. We have sell some products of different custom boxes.it is very useful and very low price please visits this site thanks and please share this post with your friends. DXTECH

    ReplyDelete