我正在尝试解决Google Apac过去的问题,我已经从文件中读取了no.of测试用例为100的输入,但它只生成2个输出案例,任何人都可以帮忙吗? 试图从上周解决,但无法获得所需的输出文件。 代码发布在下面,任何帮助将非常感谢 谢谢
import java.io.*;
import java.util.*;
class Jam
{
public static void main(String args[]) throws IOException
{
Scanner sc = new Scanner(new
FileReader("C:/Users/AAKASH/eclipse/Downloads/A-small-practice-1.in"));
PrintWriter pw = new PrintWriter(new
FileWriter("C:/Users/AAKASH/eclipse/Downloads/A-small-practice-1.out"));
HashSet<String>hset=new HashSet<String>();
int T=sc.nextInt();
sc.nextLine();
for(int i=1;i<=T;i++)
{
int M=sc.nextInt();
sc.nextLine();
if(M>=1&&M<=10)
{
int d=2*M;
String Name[]=new String[d];
for(int j=0;j<d;j++)
{
Name[j]=sc.next();
hset.add(Name[j]);
}
if(hset.size()<Name.length)
{
pw.println("Case #"+i+":"+" "+"NO");
}
if(hset.size()==Name.length)
{
pw.println("Case #"+i+":"+" "+"YES");
}
}
}
pw.flush();
pw.close();
sc.close();
}
}
答案 0 :(得分:0)
我对main方法做了一些更改,现在它为所有测试用例生成结果,但是你需要验证逻辑和输出。
public static void main(String args[]) throws IOException {
Scanner sc = new Scanner(new FileReader("D:/A-small-practice-1.in"));
PrintWriter pw = new PrintWriter(new FileWriter("D:/A-small-practice-1.out"));
HashSet<String> hset = new HashSet<String>();
int T = Integer.parseInt(sc.nextLine().trim());
for (int i = 1; i <= T; i++) {
String str = sc.nextLine().trim();
int M = Integer.parseInt(str);
if (M >= 1 && M <= 10) {
int d = 2 * M;
String Name[] = new String[d];
for (int j = 0; j < d; j++) {
Name[j] = sc.next();
hset.add(Name[j]);
}
if (hset.size() == Name.length) {
pw.println("Case #" + i + ":" + " " + "YES");
} else {
pw.println("Case #" + i + ":" + " " + "NO");
}
}
sc.nextLine();
}
pw.flush();
pw.close();
sc.close();
}