Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/377.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
为什么测试用例在这方面显示错误? import java.util.*; 公营足球{ 公共静态void main(字符串参数[]){ int top=-1; 最终整数最大值=10000000; int stack[]=新的int[MAX]; //基于堆栈 扫描仪sc=新的扫描仪(System.in); int-cases,n,id; 案例=sc.nextInt(); 对于(int i=0;i=MAX){ 系统出口(0); }否则{ top++; 堆栈[top]=id; } 对于(int j=0;j_Java_Data Structures_Stack - Fatal编程技术网

为什么测试用例在这方面显示错误? import java.util.*; 公营足球{ 公共静态void main(字符串参数[]){ int top=-1; 最终整数最大值=10000000; int stack[]=新的int[MAX]; //基于堆栈 扫描仪sc=新的扫描仪(System.in); int-cases,n,id; 案例=sc.nextInt(); 对于(int i=0;i=MAX){ 系统出口(0); }否则{ top++; 堆栈[top]=id; } 对于(int j=0;j

为什么测试用例在这方面显示错误? import java.util.*; 公营足球{ 公共静态void main(字符串参数[]){ int top=-1; 最终整数最大值=10000000; int stack[]=新的int[MAX]; //基于堆栈 扫描仪sc=新的扫描仪(System.in); int-cases,n,id; 案例=sc.nextInt(); 对于(int i=0;i=MAX){ 系统出口(0); }否则{ top++; 堆栈[top]=id; } 对于(int j=0;j,java,data-structures,stack,Java,Data Structures,Stack,这就是你需要做的,但这不是stack two的好例子,简单变量是你跟踪最后一个拥有量所需要的。错误是…?@guy我不知道,错误是什么,虽然我的示例测试用例通过了,但示例测试用例没有通过,并显示这是一个错误的答案。你希望我们如何识别代码的原因当我们不知道它应该做什么的时候,它没有产生预期的输出吗?@Guy是problem@Andreas,刚给你提供了链接兄弟,请查收 import java.util.*; public class football{ public static void main

这就是你需要做的,但这不是stack two的好例子,简单变量是你跟踪最后一个拥有量所需要的。

错误是…?@guy我不知道,错误是什么,虽然我的示例测试用例通过了,但示例测试用例没有通过,并显示这是一个错误的答案。你希望我们如何识别代码的原因当我们不知道它应该做什么的时候,它没有产生预期的输出吗?@Guy是problem@Andreas,刚给你提供了链接兄弟,请查收
import java.util.*;
public class football{
public static void main(String args[]){
    int top=-1;
    final int MAX=10000000;
    int stack[]=new int[MAX];
//based on stacks
    Scanner sc=new Scanner(System.in);
    int cases,n,id;
    cases=sc.nextInt();
    for(int i=0;i<cases;i++){
        n=sc.nextInt();
        id=sc.nextInt();
        if(top>=MAX){
            System.exit(0);
        }else{
            top++;
            stack[top]=id;
        }
        for(int j=0;j<n;j++){
            char q;
            q=sc.next().charAt(0);
            if(q=='P'){
                id=sc.nextInt();
                top++;
                stack[top]=id;
            }else if(q=='B'){
                int temp=stack[top];
                top=top++;
                stack[top]=temp;
                continue;
            }

        }
        System.out.println("Player "+stack[top]);

        }
    }
}
}else if(q=='B'){
            int temp=stack[top-1];
            top++;
            stack[top]=temp;
            continue;
        }