java - java中Hackerearth问题中的NZEC错误
问题描述
我曾尝试通过互联网搜索,但找不到解决我问题的理想解决方案
这是我的代码:
String a = new String();
String b = new String();
a = sc.nextLine();
b = sc.nextLine();
int t = sc.nextInt();
int check = 0;
int againCheck =0;
for (int k =0; k<t; k++)
{
for (int i =0; i<a.length(); i++)
{
char ch = a.charAt(i);
for (int j =0; j<b.length(); j++)
{
check =0;
if (ch != b.charAt(j))
{
check=1;
}
}
againCheck += check;
}
}
System.out.println(againCheck*againCheck);
我希望输出为 4,但它显示“NZEC”错误
任何人都可以帮助我吗?
解决方案
要求规定1输入是一个数字 (N),后跟 2 x N 行。您的代码正在读取两个字符串,后跟一个数字。InputMismatchException
当它试图将输入的第 3 行解析为数字时,它可能会抛出一个错误。
提示:
- 仔细阅读要求是值得的。
- 阅读 CodeChef 上有关如何调试 NZEC 的文章:https ://discuss.codechef.com/t/tutorial-how-to-debug-an-nzec-error/11221 。它解释了诸如在代码中捕获异常和打印出 Java 堆栈跟踪等技术,以便您了解发生了什么问题。
1 - 诚然,要求并不十分明确。但是在示例输入中,第一行是一个数字。
推荐阅读
- javascript - Joomla jQuery 未定义
- excel - 将 VBA 中的数字修改为字母,使单词不以“one”开头
- reactjs - 平面列表 - ScrollToIndex 应与 getItemLayout 或 onScrollToIndexFailed 一起使用
- c++ - 在 TListView 中始终显示滚动条
- database - CRecordset::GetFieldValue() 抛出异常(但并非总是如此)
- android - Android:Volley NoClassDefFoundError
- javascript - 如何在 ReactJs 中组合样式属性
- c++ - VC++ 本机单元测试,找不到调试符号
- php - 作曲家在设置了 setuid 位的情况下以非 root 用户身份运行时发出错误警告
- docker - Kafka docker 无法开始使用 spotify