以下Java代码在eclipse中能够正常运行,但在刷题平台中无法运行,暂未找到问题在哪里
import java.util.HashMap;
import java.util.LinkedList;
import java.util.Scanner;
public class Main {
static class Window{ //窗口类
int pid;
int top,left;
int height,width;
//全参构造器
public Window(int pid,int top,int left,int height,int width) {
this.pid=pid;
this.top=top;
this.left=left;
this.height=height;
this.width=width;
}
}
public static void main(String[] args) {
//数据输入
Scanner sc = new Scanner(System.in);
String[] nm = sc.nextLine().split(" ");
int n = Integer.parseInt(nm[0]);
int m = Integer.parseInt(nm[1]);
int k = Integer.parseInt(sc.nextLine());
String[] ops = new String[k];
for(int i=0; i<k ; i++) {
ops[i] = sc.nextLine();
}
sc.close();
LinkedList<Window> list = new LinkedList<>(); //顶层窗口放在链表尾部
HashMap<Integer,Window> map = new HashMap<>(); //辅助获取某个窗口
//处理操作指令
for(int i=0; i<k ; i++) {
String[] op = ops[i].split(" ");
int pid;
int param1,param2,param3,param4;
if(op[0].equals("new")) {
pid = Integer.parseInt(op[1]);
param1 = Integer.parseInt(op[2]);
param2 = Integer.parseInt(op[3]);
param3 = Integer.parseInt(op[4]);
param4 = Integer.parseInt(op[5]);
Window window = new Window(pid,param1,param2,param3,param4);
list.add(window);
map.put(pid, window);
}else if(op[0].equals("move")) {
pid = Integer.parseInt(op[1]);
param1 = Integer.parseInt(op[2]);
param2 = Integer.parseInt(op[3]);
Window window = map.get(pid);
list.remove(window);
Window newWindow = new Window(pid , window.top+param1 , window.left+param2 , window.height , window.width);
list.add(newWindow);
map.remove(pid);
map.put(pid,newWindow);
}else if(op[0].equals("resize")) {
pid = Integer.parseInt(op[1]);
param1 = Integer.parseInt(op[2]);
param2 = Integer.parseInt(op[3]);
Window window = map.get(pid);
list.remove(window);
Window newWindow = new Window(pid , window.top , window.left , param1 , param2);
list.add(newWindow);
map.remove(pid);
map.put(pid,newWindow);
}else if(op[0].equals("close")) {
pid = Integer.parseInt(op[1]);
Window window = map.get(pid);
list.remove(window);
map.remove(pid);
}else if(op[0].equals("active")) {
pid = Integer.parseInt(op[1]);
Window window = map.get(pid);
list.remove(window);
list.add(window);
}
}
//初始化
char[][] paint = new char[n][m];
for(int i=0 ; i<n ; i++) {
for(int j=0 ; j<m ; j++) {
paint[i][j] = '.';
}
}
while(list.size()!=0) {
//取出链表头部窗口,此窗口在较底层
Window last = list.getFirst();
list.removeFirst();
int top = last.top;
int left = last.left;
int height = last.height;
int width = last.width;
//画顶点(每个顶点需要其所在的两条边不出界才能画
if(top>=0 && top<n && left>=0 && left<m) paint[top][left] = '+';
if(top>=0 && top<n && left+width-1>=0 && left+width-1<m) paint[top][left+width-1] = '+';
if(top+height-1>=0 && top+height-1<n && left>=0 && left<m) paint[top+height-1][left] = '+';
if(top+height-1>=0 && top+height-1<n && left+width-1>=0 && left+width-1<m) paint[top+height-1][left+width-1] = '+';
//画边
for(int i=left+1 ; i<=left+width-2 && i>=0 && i<m ; i++) {
paint[top][i] = '-'; //上横边
paint[top+height-1][i] = '-'; //下横边
}
for(int i=top+1 ; i<=top+height-2 && i>=0 && i<n ; i++) {
paint[i][left] = '|'; //左竖边
paint[i][left+width-1] = '|'; //右竖边
}
}
//输出
for(int i=0 ; i<n ; i++) {
for(int j=0 ; j<m ; j++) {
System.out.print(paint[i][j]);;
}
System.out.println();
}
/**
* 一个测试用例
7 10
8
new 1 0 3 2 5
new 2 4 4 2 5
new 3 3 3 4 6
resize 3 3 6
move 1 0 5
close 2
new 4 1 1 3 5
active 3
*/
}
}