Skip to content

Instantly share code, notes, and snippets.

@KazumasaSUGAYA
Created October 28, 2012 09:33
Show Gist options
  • Save KazumasaSUGAYA/3968172 to your computer and use it in GitHub Desktop.
Save KazumasaSUGAYA/3968172 to your computer and use it in GitHub Desktop.
Stacking Blocks I
【Stacking Blocks I】
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=10032
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Stack;
public class StackingBlocks {
/**
* @param args
* @throws IOException
*/
public static void main(String[] args) throws IOException {
Stack<String> stack = new Stack<String>();
System.out.println(" コマンド(push or pop)を入力してください。 : ");
InputStreamReader reader = new InputStreamReader(System.in);
BufferedReader br = new BufferedReader(reader);
while(true){
String command = br.readLine();
if(command.equals("quit")){
break;
}else if(command.equals("push")){
//System.out.println(command);
stack.push(command);
}else if(command.equals("pop")){
//st.pop();
if(!(stack.empty())){
System.out.println(stack.pop());
}else{
System.out.println("stack is empty");
}
}else{
break;
}
}
}
}
@KazumasaSUGAYA
Copy link
Author

スタックを自分で実装する。スタッククラスを使わない。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment