
Originally Posted by
OptionBase1
The wording of the program description seems to imply the source data is stored in a file, and you don't appear to have any file i/o code at all, just user input.
Also,
you don't appear to have any code that does anything at all with these input values.
They said
The program will be tested against the hidden test cases. You may assume that all test cases use valid inputs (no input error trapping is required).
hence I am not testing if the input is correct or not. I am not even sure what is the usage of the 1st line, should I use it to determine if the succeeding lines are of the correct size or not?
I've just tried reading from their input files and still this is failing. I am not sure what I am doing wrong.
Code:
import java.io.BufferedWriter;
import java.io.FileWriter;
import java.util.Scanner;
class solution {
public static void main(String[] args) {
try {
Scanner scanner = new Scanner(new java.io.File("000.in"));
String MN = scanner.nextLine();
String N = scanner.nextLine();
String M = scanner.nextLine();
scanner.close();
String N2 = N.replace(" ", "XX");
String[] tempArray;
String delimiter = " ";
tempArray = M.split(delimiter);
int occurence = 0;
for (int i = 0; i < tempArray.length; i++)
{
if (N2.contains(tempArray[i]))
occurence += 1;
} System.out.println(occurence);
String str1 = Integer.toString(occurence);
BufferedWriter out = new BufferedWriter(new FileWriter("." + java.io.File.separator + "000.ans"));
out.write(str1);
out.newLine();
out.close();
} catch (Exception ex) {
} finally {
}
return;
}
}