[伴随编程] Q的书房 I
You cannot submit for this problem because the contest is ended. You can click "Open in Problem Set" to view this problem in normal mode.
Q的书房里有 n本书,每本书有一个编号和书名。现在请你用动态数组储存所有的书,并按照编号从大到小输出所有书名。
代码中已经给出了Book结构体,表示每本书的信息,包含一个int类型的编号,和一个string类型的书名。cmp函数是用来给所有书按编号从大到小排序,最后我们会按顺序输出所有书的书名。
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
struct Book {
int id;
string name;
};
bool cmp(Book p1, Book p2) {
return p1.id > p2.id;
}
int main() {
int n;
cin >> n;
for (int i = 0; i < n; i++) {
cout << books[i].name << endl;
}
return 0;
}
输入格式
输入两行;
第一行一个整数n,表示有n本书。
接下来一共 n行,每行一个整数 id和一个字符串name,id表示这本书的编号,name表示这本书的名字。
输出格式
输出n行,按编号从大到小输出n本书的书名,每个书名占一行。
样例输入1
5
20 C++
27 PHP
19 Java
35 Python
13 C#
样例输出1
Python
PHP
C++
Java
C#
2024022001
- Status
- Done
- Rule
- ACM/ICPC
- Problem
- 9
- Start at
- 2024-2-20 17:00
- End at
- 2024-2-20 18:18
- Duration
- 1.3 hour(s)
- Host
- Partic.
- 12