做完没时间编译,大家看看这个代码能对百分之多少?
import java.util.Scanner;
publicclass Main {
staticclass Item {
int
type = 0;
boolean
isUse
= false;
public Item(int t, boolean b) {
type = t;
isUse= b;
}
}
public
static
void main(String[] args) {
Scanner s = new
Scanner(System.in);
while (s.hasNext()) {
int times = s.nextInt();
int size = s.nextInt();
int count = 1;
Item data[] = new Item[size];
for (int i = 0; i < size; i++) {
data[i] = new Item(0, false);
}
int now = 0;
while (now < times) {
now++;
String com = s.next();
if (com.equals("new")) {
int d = s.nextInt();
int i = 0;
for (i = size - 1; i >= 0; i--) {
if (data[i].isUse == true)
break;
}
if (i + 1 <= size - 1) {
if (size - (i + 1) >= d) {
for (int j = 0; j < d; j++) {
data[j + i +1] = new Item(count,
true);
}
System.out.println(count++);
} else {
System.out.println("NULL");
}
}
} else
if (com.equals("del")){
int tt = s.nextInt();
boolean isT = false;
for (int i = 0; i < size; i++) {
if (data[i].type == tt) {
data[i].isUse = false;
isT = true;
}
}
if (isT == false) {
System.out.println("ILLEGAL_OPERATION");
}
} else
if (com.equals("def")) {
Item two[] = new Item[size];
for (int i = 0; i < size; i++) {
two[i] = new Item(0, false);
}
int tii = 0;
for (int i = 0; i < size; i++) {
if (data[i].isUse == true) {
two[tii].isUse = true;
two[tii].type = data[i].type;
tii++;
}
}
data = two;
}
}
}
}
}