java - 以下代码在 ideone 中出现运行时错误,但在 eclipse 和 bash 终端中运行良好
问题描述
我正在运行代码来计算BigInteger
String 中的一些值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);
}
}
解决方案
推荐阅读
- ios - 将数据从 UITableViewCell 传递到 ViewController
- python - 抓取(法语)动词变位并将它们导入 org-mode(与 org-drill 一起使用)
- python - python - matplotlib.pyplot 用 4 个通道保存二进制掩码(?)
- amazon-web-services - 未捕获:TypeError:AWS.CognitoIdentityCredentials 不是构造函数
- github - 将数据从 GoogleColab 上传到 GitHub 或 Kaggle
- javascript - 在 www.facebook.com 上运行的浏览器扩展的 Facebook 登录
- c - How to write C program that attaches/detaches from Unix terminal?
- python - TypeError: 不支持的操作数类型 -: 'int' and 'str' with a datetime module
- javascript - 如何从 HTML 输入字段中旋转 jpeg 文件并将其保存为 base64 字符串
- google-chrome - A2HS 停止触发任何 PWA。是否有触发 A2HS 的实际规格?