标签:int scan system system.in code color int() ann ++
题目:http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1289
从左往右将数字压入栈里(想象成一个水平向右的栈),如果鱼是向左的让它一直吃,直到被吃或者吃完为止
import java.util.Scanner; import java.util.Stack; public class N1289 { private static Scanner cin; public static void main(String[] args) { cin = new Scanner(System.in); int n=cin.nextInt(),ans=n,size,dir; Stack<Integer> s=new Stack<Integer>(); for(int i=0;i<n;i++) { size=cin.nextInt(); dir=cin.nextInt(); if(dir==1) s.push(new Integer(size)); else { while(s.empty()!=true) { if(size>Integer.parseInt(s.peek().toString())) { s.pop(); ans--; } else { ans--; break; } } } } System.out.println(ans); } }
标签:int scan system system.in code color int() ann ++
原文地址:http://www.cnblogs.com/NDKY9/p/7535366.html