运行Java程序的时候,用Scanner输入几行数据始终无法结束输入是怎么回事?
比如一下代码,运行的时候一直无法结束输入publicclassMain{privateintN,M,T;privateorderNodeorder[];privatein...
比如一下代码,运行的时候一直无法结束输入
public class Main {
private int N, M, T;
private orderNode order[];
private int priority[];
private boolean buffer[];
public Main() {
Scanner sc = new Scanner(System.in);
String s[] = sc.nextLine().split(" ");
N = Integer.parseInt(s[0]);
M = Integer.parseInt(s[1]);
T = Integer.parseInt(s[2]);
System.out.println(M);
order = new orderNode[T];
priority = new int[N];
buffer = new boolean[N];
for (int i = 0; i < T; i++) {
order[i] = new orderNode();
order[i].first = null;
}
for (int i = 0; i < N; i++) {
priority[i] = 0;
buffer[i] = false;
}
storeNode p;
for (int i = 0; i < M; i++) {
s = sc.nextLine().split(" ");
p = new storeNode();
p.number = Integer.parseInt(s[1]);
p.next = order[Integer.parseInt(s[0]) - 1].first;
order[Integer.parseInt(s[0]) - 1].first = p;
}
}
private int orderCount(int number, int time) {
int count = 0;
storeNode p = order[time - 1].first;
while (p != null) {
if (p.number == number) {
count++;
}
}
return count;
}
private void attend() {
for (int i = 0; i < T; i++) {
for (int j = 0; j < N; j++) {
if (orderCount(j + 1, i + 1) == 0) {
if (priority[j] != 0) {
priority[i]--;
}
} else {
priority[j] += 2 * orderCount(j + 1, i + 1);
}
if (priority[j] > 5) {
buffer[j] = true;
} else if (priority[j] <= 3) {
buffer[j] = false;
} else {
// do no operation;
}
}
}
}
private void showResult() {
int count = 0;
for (int i = 0; i < N; i++) {
if (buffer[i]) {
count++;
}
}
System.out.println(count);
}
public static void main(String[] args) {
Main example = new Main();
example.attend();
example.showResult();
}
} 展开
public class Main {
private int N, M, T;
private orderNode order[];
private int priority[];
private boolean buffer[];
public Main() {
Scanner sc = new Scanner(System.in);
String s[] = sc.nextLine().split(" ");
N = Integer.parseInt(s[0]);
M = Integer.parseInt(s[1]);
T = Integer.parseInt(s[2]);
System.out.println(M);
order = new orderNode[T];
priority = new int[N];
buffer = new boolean[N];
for (int i = 0; i < T; i++) {
order[i] = new orderNode();
order[i].first = null;
}
for (int i = 0; i < N; i++) {
priority[i] = 0;
buffer[i] = false;
}
storeNode p;
for (int i = 0; i < M; i++) {
s = sc.nextLine().split(" ");
p = new storeNode();
p.number = Integer.parseInt(s[1]);
p.next = order[Integer.parseInt(s[0]) - 1].first;
order[Integer.parseInt(s[0]) - 1].first = p;
}
}
private int orderCount(int number, int time) {
int count = 0;
storeNode p = order[time - 1].first;
while (p != null) {
if (p.number == number) {
count++;
}
}
return count;
}
private void attend() {
for (int i = 0; i < T; i++) {
for (int j = 0; j < N; j++) {
if (orderCount(j + 1, i + 1) == 0) {
if (priority[j] != 0) {
priority[i]--;
}
} else {
priority[j] += 2 * orderCount(j + 1, i + 1);
}
if (priority[j] > 5) {
buffer[j] = true;
} else if (priority[j] <= 3) {
buffer[j] = false;
} else {
// do no operation;
}
}
}
}
private void showResult() {
int count = 0;
for (int i = 0; i < N; i++) {
if (buffer[i]) {
count++;
}
}
System.out.println(count);
}
public static void main(String[] args) {
Main example = new Main();
example.attend();
example.showResult();
}
} 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询