英文:
I want to know why the program worked in eclipse but was not able to submit in Codejam
问题
import java.util.Scanner;
public class Solution {
public static void main(String args[]) {
int T=0;
Scanner a = new Scanner(System.in);
T = a.nextInt();
int cases=0;
String work[][] = new String[T][1000];
String data[] = new String[T];
while(T > cases) {
int N=a.nextInt();
int J[][] = new int[N][2];
int C[][] = new int[N][2];
for(int i=0;i<N;i++) {
int Si = a.nextInt();
int Ei = a.nextInt();
boolean check = true;
boolean check1 =true;
for(int k=0;k<i;k++) {
if(Si >= J[k][0] && Si < J[k][1]) {
check=false;
}
if(Ei > J[k][0] && Ei <= J[k][1]) {
check=false;
}
if(Si >= C[k][0] && Si < C[k][1]) {
check1=false;
}
if(Ei > C[k][0] && Ei <= C[k][1]) {
check1=false;
}
}
if(check) {
J[i][0] = Si;
J[i][1] = Ei;
work[cases][i] = "J";
} else if(check1) {
C[i][0] = Si;
C[i][1] = Ei;
work[cases][i] = "C";
} else
work[cases][i] = "I";
}
for(int k=0;k<N;k++) {
if(k==0)
data[cases] = work[cases][k];
else
data[cases] += work[cases][k];
}
cases++;
}
for(int k=0;k<T;k++) {
if(data[k].contains("I")) {
data[k] = "Impossible";
}
}
for(int i=0;i<T;i++) {
System.out.println("Case #" + (i+1) + ": " + data[i]);
}
}
}
英文:
I tried to attend in google code jam and in qualification round when I submit it I got WA(Wrong Answer). When it worked fine in my eclipse can I know the problem with my code so I can fix my code. I also got the correct output when I tried to test my program with sample input and output.
Input
4
3
360 480
420 540
600 660
3
0 1440
1 3
2 4
5
99 150
1 100
100 301
2 5
150 250
2
0 720
720 1440
Output
Case #1: CJC
Case #2: IMPOSSIBLE
Case #3: JCCJJ
Case #4: CC
import java.util.Scanner;
public class Solution {
public static void main(String args[]) {
int T=0;
Scanner a = new Scanner(System.in);
T = a.nextInt();
int cases=0;
String work[][] = new String[T][1000];
String data[] = new String[T];
while(T>cases) {
//System.out.println("cases: "+cases);//debug
int N=a.nextInt();
int J[][] = new int[N][2];
int C[][] = new int[N][2];
for(int i=0;i<N;i++) {
//System.out.println("For : i"+ i);//debug
int Si = a.nextInt();
int Ei = a.nextInt();
boolean check = true;
boolean check1 =true;
for(int k=0;k<i;k++) {
if(Si>=J[k][0]&&Si<J[k][1]) {
check=false;
}
if(Ei>J[k][0]&&Ei<=J[k][1]) {
check=false;
}
if(Si>=C[k][0]&&Si<C[k][1]) {
check1=false;
}
if(Ei>C[k][0]&&Ei<=C[k][1]) {
check1=false;
}
}
if(check) {
//System.out.println("Upgrade1");
J[i][0] = Si;
J[i][1] = Ei;
work[cases][i] = "J";
}else if(check1) {
//System.out.println("Upgrade2");
C[i][0] = Si;
C[i][1] = Ei;
work[cases][i] = "C";
}else
work[cases][i]= "I";
}
for(int k=0;k<N;k++) {
//System.out.println("N: "+ N);
if(k==0)
data[cases] = work[cases][k];
else
data[cases]+=work[cases][k];
}
cases++;
}
for(int k=0;k<T;k++) {
if(data[k].contains("I")) {
data[k]="Impossible";
}
}
for(int i=0;i<T;i++) {
//System.out.println("Printing");
System.out.println("Case #" + (i+1) + ": "+ data[i]);
}
}
}
</details>
专注分享java语言的经验与见解,让所有开发者获益!
评论