L1-005. 考試座位號

L1-005. 考試座位號

######問題描述:

Paste_Image.png

java代碼:
import java.util.Scanner;

/**考試座位號
 * Created by pc on 17-3-12.
 */
public class Main {
    public static void main (String[] args){
        Scanner input = new Scanner (System.in);
        int a=input.nextInt();
        String b[]=new String [a];
        int c[] = new int[a];
        int d[]= new int[a];

        for(int i= 0; i<a;i++){//依次存入信息
            b[i]=input.next();
            c[i]=input.nextInt();
            d[i]=input.nextInt();
        }
        int e=input.nextInt();//查找的個數
        int f[]=new int[e];
        for (int i=0 ; i<e;i++){
            f[i]=input.nextInt();//要查找的試機號
        }

        for(int i=0; i<e;i++){
            for (int j=0;j<a;j++){
                if(f[i]==c[j]){
                    System.out.println(b[j]+" "+d[j]);
                }
            }
        }
    }
}
結果[結果部分顯示超時,如果可以優化該代碼,可以給我留言]

Paste_Image.png

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章