I don’t see anything wrong with my code, but I can only get through the first test case. Any suggestions?
import java.util.*;
import java.io.*;
public class Test {
public static void main(String[] args) throws IOException{
File text = new File("gymnastics.in");
Scanner input = new Scanner(text);
File outFile = new File ("gymnastics.out");
FileWriter fWriter = new FileWriter (outFile);
PrintWriter pWriter = new PrintWriter (fWriter);
int K = input.nextInt(); int N = input.nextInt();
String[] sessions = new String[K];
input.nextLine();
for (int i=0; i<K; i++) {
sessions[i] = input.nextLine();
}
int count = 0;
for (int a=1; a<=N; a++) {
for (int b=1; b<=N; b++) {
int c = 0;
String a_ = a + "";
String b_ = b + "";
for (int i=0; i<K; i++) {
if (sessions[i].indexOf(a_) < sessions[i].indexOf(b_)) {
c++;
}
}
if (c==K) {
//System.out.println(a + " " + b);
count++;
}
}
}
pWriter.println(count);
pWriter.close();
}
}