这是我对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/