PAT1009 说反话 (20)

这个题我用C++写总是处错误,所以就用java内置的输入写了一个,应该属于投机取巧。

import java.util.Stack;
import java.util.Scanner;
import java.util.StringTokenizer;

public class Main {
	public static String input;
	public static Stack<String> myStack;
	
	public static void main(String []args)
	{
		myStack=new Stack<String>();
		Scanner cin=new Scanner(System.in);
		input=cin.nextLine();
		StringTokenizer stringTokenizer =new StringTokenizer(input);
		while(stringTokenizer.hasMoreTokens())
		{
			myStack.push(stringTokenizer.nextToken());
		}
		
		
		boolean first=true;
		while(!myStack.isEmpty())
		{
			if(first)
			{
				first=false;
			}
			else
			{
				System.out.print(' ');
			}
			System.out.print(myStack.pop());
		}
		
	}
}


你可能感兴趣的:(PAT1009 说反话 (20))