java - 对于此代码,使用 Java 在 SPOJ 中获取 NZEC 错误

标签 java

这是我对SPOJ(题号:12156)一半题的一半的回答。我是 JAVA 的初学者。请帮助我为什么会收到错误消息。在 Ideone 中编译时,我能够得到预期的答案。谢谢

import java.util.*;
import java.lang.*;
import java.io.*;


class Ideone
{
    public static void main (String[] args) throws java.lang.Exception
    {
        Scanner scan =new Scanner(System.in);
        String[] name= new String[10];
        int size,count;
        String temp,news;
        char[] chars= new char[20];

        temp=scan.nextLine();
        count=Integer.parseInt(temp);

            for(int i=0;i<count;i++)
            {
                name[i]=scan.nextLine();
            }

                for(int j=0;j<count;j++)
                {
                    news=name[j];
                    size=news.length();
                    chars=news.toCharArray();
                        for(int k=0;k<size/2;k=k+2)
                            {
                                System.out.print(chars[k]);
                            }
                            System.out.println();
                }


    }
}

最佳答案

问题描述中注意以下几点:

In the first line of input your are given the positive integer t (1 <= t <= 100) - the number of test cases.

在您的代码中,您最多可以处理 10 个(而不是 100 个)字符串。
String[] name = new String[10];

In the each of the next t lines, you are given a sequence of 2*k (1 <= k <= 100) characters.

在您的代码中,您最多可以处理 20 个(而不是 200 个)字符。
char[] chars = new char[20];

关于java - 对于此代码,使用 Java 在 SPOJ 中获取 NZEC 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33671148/

相关文章:

java - 剪刀石头布游戏 3 中最佳 2 循环问题

java - 确定哪种类型的异常是可抛出的

java - 用 Java 中的对象列表迭代对象的最佳方法

java - 无法在另一个包中加载 FXML (JavaFX)

java - 将单例设计模式实现为模板

java - 类与 JPA 的关系

java - 在 Netty 的管道之外使用 DelimiterBasedFrameDecoder、StringEncoder 等

java - 在 Java 中向 Thread 类添加函数

Java图形问题

java - 无限 while 循环以及读取文件时出现问题