PTA 乙級 1041 考試座位號 (15分) C++
阿新 • • 發佈:2020-07-28
建立學生考試資訊結構體,根據輸入的n,建立結構體陣列
C++
1 #include<iostream> 2 #include<vector> 3 4 using namespace std; 5 6 //學生資訊結構體 7 typedef struct { 8 string exam; 9 int sn; 10 int seat; 11 }Student; 12 13 int main() { 14 int n = 0, m = 0, num = 0; 15 cin >> n;16 vector<Student> all(n); //建立n個學生資訊結構體陣列,儲存學生資訊方便後續輸出 17 for (int i = 0; i < n; ++i) { 18 cin >> all[i].exam >> all[i].sn >> all[i].seat; //輸入學生資訊 19 } 20 cin >> m; 21 for (int i = 0; i < m; ++i) { 22 cin >> num;23 for (int j = 0; j < n; j++) { 24 if (all[j].sn == num) //找到對應試機座位號輸出 25 cout << all[j].exam << " " << all[j].seat << endl; 26 } 27 } 28 return 0; 29 }
水的一題,就是題幹有點麻煩