Java 为什么我在一个在线法官身上犯了NZEC错误?

Java 为什么我在一个在线法官身上犯了NZEC错误?,java,Java,我写的代码在互联网上随处可见。但是在Codechef上,它显示了一个NZEC错误。我不明白为什么。我已经尝试了很多测试用例,我在我的计算机上或任何在线的地方都能得到预期的输出。请帮忙。 下面是我的源代码: import java.util.Scanner; class abc{ public static void main(String a[]) { Scanner sc = new Scanner(System.in); int

我写的代码在互联网上随处可见。但是在Codechef上,它显示了一个NZEC错误。我不明白为什么。我已经尝试了很多测试用例,我在我的计算机上或任何在线的地方都能得到预期的输出。请帮忙。 下面是我的源代码:

import java.util.Scanner;

class abc{
    public static void main(String a[])
    {
    Scanner sc = new Scanner(System.in);


                int t = Integer.parseInt(sc.next());
    int scount=0,mcount=0;

    while(t!=0)
    {

    scount=0;
    mcount=0;

    String str=sc.next();


    for(int i=0;i<str.length();i++)
    {

        if(str.charAt(i)=='m')
            {
                mcount++;
                if(i==0)
                    {
                        if(str.charAt(1)=='s')
                        scount--;
                    }
                else if(i==(str.length()-1))
                    {
                        if(str.charAt(i-1)=='s')
                        scount--;
                    }
                else 
                    if(str.charAt(i-1)=='s')
                    scount--;
                else 
                    if (str.charAt(i+1)=='s')
                    scount--;

            }
        else if(str.charAt(i)=='s')
            scount++;

    }


    if(scount==mcount)
        System.out.println("tie");
    else if(scount>mcount)
        System.out.println("snakes");
    else
        System.out.println("mongooses");

    t--;
    }

}
}
import java.util.Scanner;
abc班{
公共静态void main(字符串a[]
{
扫描仪sc=新的扫描仪(System.in);
int t=Integer.parseInt(sc.next());
int-scont=0,mcount=0;
while(t!=0)
{
Scont=0;
mcount=0;
字符串str=sc.next();
对于(int i=0;imcount)
System.out.println(“蛇”);
其他的
System.out.println(“猫鼬”);
t--;
}
}
}

错误确切地说是什么?它只是说“运行时错误”:NZEC(非零退出代码)您的算法有缺陷。根据问题描述,如果您输入“msmsss”,结果应该是“tie”(因为最多只能吃两条蛇),但您的代码将输出“mongooses”。@ThomasKläger Yupp。知道了。当一条蛇已经被左边的猫鼬吃掉时,我不得不加上一些限制,因为它不能被右边的猫鼬吃掉。谢谢你的帮助。