我正在运行代码以计算字符串BigInteger
中的某些ArrayList
值。计算是在ArrayList
之外进行的,然后作为字符串添加回列表中。
该代码可通过Ubuntu终端和Eclipse IDE正常运行,但在Ideone和其他在线IDE中会出现运行时错误。
public static void main (String[] args) throws IOException
{
BufferedReader kb = new BufferedReader(new InputStreamReader(System.in));
int T = Integer.parseInt(kb.readLine());
for(int i = 0; i<T; i++){
int N = Integer.parseInt(kb.readLine());
ArrayList<String> L = new ArrayList();
//int[] L = new int[N];
for(int j = 0; j<N; j++){
L.add(Integer.toString(j+1));
}
while(L.size()>1){
BigInteger x = new BigInteger(L.get(0).substring(0));
BigInteger y = new BigInteger(L.get(L.size()-1).substring(0));
L.remove(0);
L.remove(L.size()-1);
BigInteger fin = new BigInteger("0");
fin = fin.add(x);
fin = fin.add(y);
fin = fin.add(x.multiply(y));
String finstring = fin.toString();
L.add(finstring);
}
int r = 0;
for(int j = 0; j<L.get(0).length(); j++) {
r = (r * 10 + (int)L.get(0).charAt(j) - '0') % 100000007;
}
System.out.println(r);
}
}
答案 0 :(得分:1)