我想知道为什么这个程序在Eclipse中运行正常,但无法在Codejam中提交。

huangapple 未分类评论48阅读模式
英文:

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&gt;cases) {
			//System.out.println(&quot;cases: &quot;+cases);//debug
			int N=a.nextInt();
			int J[][] = new int[N][2];
			int C[][] = new int[N][2];
			for(int i=0;i&lt;N;i++) {
				//System.out.println(&quot;For : i&quot;+ i);//debug
				int Si = a.nextInt();
				int Ei = a.nextInt();
				boolean check = true;
				boolean check1 =true;
				for(int k=0;k&lt;i;k++) {
					if(Si&gt;=J[k][0]&amp;&amp;Si&lt;J[k][1]) {
						check=false;
					}
					if(Ei&gt;J[k][0]&amp;&amp;Ei&lt;=J[k][1]) {
						check=false;
					}
					if(Si&gt;=C[k][0]&amp;&amp;Si&lt;C[k][1]) {
						check1=false;
					}
					if(Ei&gt;C[k][0]&amp;&amp;Ei&lt;=C[k][1]) {
						check1=false;
					}
				}
				if(check) {
					//System.out.println(&quot;Upgrade1&quot;);
					J[i][0] = Si;
					J[i][1] = Ei;
					work[cases][i] = &quot;J&quot;;
				}else if(check1) {
					//System.out.println(&quot;Upgrade2&quot;);
					C[i][0] = Si;
					C[i][1] = Ei; 
					work[cases][i] = &quot;C&quot;;
				}else
					work[cases][i]= &quot;I&quot;;
			}
			for(int k=0;k&lt;N;k++) {
				//System.out.println(&quot;N: &quot;+ N);
				if(k==0)
					data[cases] = work[cases][k];
				else
					data[cases]+=work[cases][k];
			}
			cases++;
		}
		for(int k=0;k&lt;T;k++) {
			if(data[k].contains(&quot;I&quot;)) {
				data[k]=&quot;Impossible&quot;;
			}
		}
		for(int i=0;i&lt;T;i++) {
			//System.out.println(&quot;Printing&quot;);
			
			System.out.println(&quot;Case #&quot; + (i+1) + &quot;: &quot;+ data[i]);			
		}
	}
}





</details>


huangapple
  • 本文由 发表于 2020年4月7日 15:25:27
  • 转载请务必保留本文链接:https://java.coder-hub.com/61074784.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定