• 个人简介

    #include #include #include using namespace std;

    // 定义一个结构体来存储每天的温度和对应的天数 struct DayInfo { int temperature; int day; };

    // 自定义比较函数,用于按温度升序排序 bool compare(const DayInfo& a, const DayInfo& b) { return a.temperature < b.temperature; }

    int main() { int n, k; // 读取未来天数n和要选择的天数k cin >> n >> k; vector days(n); // 读取每天的温度,并记录对应的天数(天数从1开始计数) for (int i = 0; i < n; i++) { cin >> days[i].temperature; days[i].day = i + 1; } // 使用sort函数对结构体向量按温度进行升序排序 sort(days.begin(), days.end(), compare); // 输出温度最低的k天的天数,并且按从小到大顺序输出 for (int i = 0; i < k; i++) { if (i < k - 1) { cout << days[i].day << " "; } else { cout << days[i].day << endl; } } return 0; }

  • 通过的题目

  • 最近活动

    This person is lazy and didn't join any contests or homework.
  • 最近编写的题解

    This person is lazy and didn't write any solutions.

题目标签

C语言入门Part1-顺序结构设计
1