題目鏈接在此。
這個題目挺直白的,直接看代碼好了。
#include<stdio.h>struct info{ char stuId[20]; int tryId; int seatId;}stu[1001];int main(){ int N; scanf("%d",&N); for(int i = 0; i < N; i++){ scanf("%s %d %d",&stu[i].stuId,&stu[i].tryId,&stu[i].seatId); } int M; scanf("%d",&M); for(int i = 0; i < M; i++){ int seatId; scanf("%d",&seatId); for(int j = 0; j < N; j++){ if(stu[j].tryId == seatId){ 改進方案這個改進方案是《算法筆記》上的思路,這種改進既節省時間,又節省了空間。 不像上面的代碼一樣,結構體中有三個變量,而是只有兩個(準考證號、座位號),試機座位號作為stu結構體的下標。 這樣一來,省去了存儲試機座位號的空間,并且不用像上面代碼那樣遍歷stu[]數組去查詢,而是直接輸出 stu[試機座位號].準考證號、stu[試機座位號].座位號 的對應信息即可。
新聞熱點
疑難解答