Ok that's what i need to do
As an employee of MCI (Mammoth Cakes Incorporated), your job is to create extremely large tiered cakes. A multi-layer birthday cake is made by making small circular cakes and laying them on top of each other.
To do your job, you are standing in front of a large conveyor belt while layers of different sizes pass in front of you. When you see the one you like, you can remove it from the conveyor belt and add it to your cake.
You can add as much to your cake as you want if you follow these rules:
Once a layer is added to your cake, it cannot be moved. (This will ruin the icing.) Thus, layers can only be added to the top of your cake.
Each layer passes in front of you only once. You can take it or leave it. If you do, you must add it to the top of the cake. If you leave him, he will move down the conveyor, never return.
Each layer in your cake should be at least smaller than the layer below. You cannot place a larger layer on top of a smaller one.
The diameters (in inches) of the layers descending along the conveyor belt will be indicated in advance. Your task is to create the highest cake using these layers. For example, suppose the following list represents the diameters of layers going down a conveyor belt: 8 16 12 6 6 10 5
, ( 8 ) . , ( 8 " 16" > 8 ").
, ( 6 "< 8" ).
( , ,
). , 4 : 8 6 6 5
, , ,
5: 16 12 6 6 5
, . N,
N , ,
. N , 0 N 100 000.
1 100 000 . , N = 0,
Sample Input
7 8 16 12 6 6 10 5
10 45 25 40 38 20 10 32 25 18 30
10 10 9 8 7 6 5 4 3 2 1
0
Sample Output
5
6
10
:
:
import java.io.*;
import java.util.*;
public class cake
{
private static String line;
private static ArrayList storage = new ArrayList();
private static Integer highestStack = 0;
public static void main(String [] args)throws IOException
{
FileReader fin = new FileReader("cake.in");
BufferedReader infile = new BufferedReader(fin);
FileWriter fout = new FileWriter("cake.out");
BufferedWriter outfile = new BufferedWriter(fout);
line = infile.readLine();
do
{
String[] temp = line.split(" ");
String number;
for(int j = temp.length-1; j!=0; j--)
{
if(Integer.parseInt(temp[j]) <= Integer.parseInt(temp[j-1]))
{
highestStack++;
}
}
storage.add(highestStack);
line = infile.readLine();
}while(!line.equals("0"));
infile.close();
outfile.close();
}
}