4.26 腾讯实习生测试题
4.26 腾讯实习生测试题 :第一个编程题本地完美运行 测试结果为0,那位大佬看看问题
import java.util.*; class Queue1{ int data[]=new int[50]; int front=0; int rear=0; public void PUSH(int x){ this.data[rear]=x; rear=rear+1; } public int SIZE(){ return rear-front; } public void POP(){ if(this.SIZE()!=0){ this.front+=1; } else System.out.println(-1); } public int TOP(){ if(this.SIZE()!=0) return this.data[front]; else return -1; } public void CLEAR(){ this.front=this.rear=0; } } public class Main{ public static void main(String[] args){ Queue1 q=new Queue1(); Scanner scr=new Scanner(System.in); int m=Integer.parseInt(scr.next()); for(int j=0;j<m;j++) { int k=Integer.parseInt(scr.next()); for (int i = 0; i < k; i++) { String s = scr.next(); if (s.equals("PUSH")) { int t = scr.nextInt(); q.PUSH(t); } else if (s.equals("POP")) q.POP(); else if (s.equals("TOP")) System.out.println(q.TOP()); else if(s.equals("SIZE")) System.out.println(q.SIZE()); else if(s.equals("CLEAR")) q.CLEAR(); } } } }