1.练习项目:
输入一个整数 n 和 n 个数字,然后按字典序升序输出这 n 个数字的所有全排列。
2.选择课程
在蓝桥云课中选择课程《16届蓝桥杯省赛无忧班(C&C++ 组)4期》,选择第STL"课程10并开始练习。
3.开始练习
(1)源码:
#include <iostream>
#include <utility>
#include <vector>
struct Person {
std::string name;
int age;
};
int main() {
std::vector<Person> people;
people.push_back({"Alice", 25});
people.push_back({"Bob", 30});
people.push_back({"Charlie", 20});
std::vector<std::pair<Person, int>> scores;
scores.push_back({people[0], 90});
scores.push_back({people[1], 85});
scores.push_back({people[2], 95});
for (const auto& pair : scores) {
std::cout << "Name: " << pair.first.name << std::endl;
std::cout << "Age: " << pair.first.age << std::endl;
std::cout << "Score: " << pair.second << std::endl;
std::cout << std::endl;
}
return 0;
}
(2)检验结果
对此代码进行检验,检验后无报错,提交此代码,判题结果为正确100分。
(3)练习心得:注意每段代码末尾的分号是否存在,如不存在则需即使补充;输入法是否切换为英语模式;语法是否错误。