链接:https://ac.nowcoder.com/acm/contest/5278/B
来源:牛客网
时间限制:C/C++ 1秒,其他语言2秒
空间限制:C/C++ 524288K,其他语言1048576K
64bit IO Format: %lld
题目描述
为了预防新型冠状病毒的侵袭,学校组织学生进行每日一报——自 2020 年 1 月 30 日 起至今,每位同学都必须上报自己的身体状况。为了简化问题,我们规定每日一报仅包含以下信息:
报送日期:固定 8 位十进制数,格式为 YYYYMMDD ,如 20200312 代表 2020 年 3 月 12 日;
学号:固定 8 位十进制数,不必追溯其具体含义,如 17122490;
体温:保留一位小数的浮点数,单位为摄氏度,介于 35.0 至 45.0 之间,如 37.1。
作为学校数据库负责人,Lemon 需要对体温异常(不低于 38.0 摄氏度)的报送消息进行整理后向上级上报备案。具体整理规则如下:将报送日期作为第一关键字降序,将体温作为第二关键字降序,将学号作为第三关键字升序排序。即在整理完成后,任意两条报送记录都有如下关系:
报送日期不一致的,则日期较近的在上,日期较久远的在下;
报送日期一致体温不一致的,则体温高的在上,体温低的在下;
报送日期和体温都一致的,则学号小的在上,学号大的在下。
你能帮助 Lemon 完成这个任务吗?
输入描述:
第一行包含一个整数 n (1 \leq n \leq 1001≤n≤100),表示需要处理的报送记录。
接下来 n 行,每行代表一条报送记录。
每一条记录包含两个整数和一个浮点数,中间空格分隔,分别表示报送日期、学号和体温,格式如题目描述中所述
输入保证所有的报送日期是 2020 年 1 月 30 日至今(2020 年 4 月 18 日)的合法日期,同一个学号不会在同一天进行多次报送。
输出描述:
第一行输出一个整数 m,表示需要上报备案的记录数量。
接下来 m 行,每行为一条记录。
记录的顺序应符合题目要求,记录格式应与输入格式中所述记录格式保持一致。
示例1
输入
复制
5
20200229 17122490 37.0
20200301 17122490 38.4
20200229 17122640 39.0
20200301 17122640 38.4
20200301 16122138 38.1
输出
复制
4
20200301 17122490 38.4
20200301 17122640 38.4
20200301 16122138 38.1
20200229 17122640 39.0
备注:
Lemon 很清楚,他其实就是要执行 SQL 查询:SELECT * FROM REPORT WHERE(temperature>=38.0) ORDER BY date DESC, temperature DESC, studentID ASC;
code:
#include <bits/stdc++.h>
using namespace std;
struct data{
int date; double tem; int code;
inline void print(){
cout << date << ' ';
cout << code << ' ';
cout << fixed << setprecision(1) << tem << '\n';
}
inline bool operator < (const data w) const{
if (date != w.date) return date > w.date;
if (abs(tem-w.tem) > 1e-3) return tem > w.tem;
return code < w.code;
}
}a[1000];
int n,m;
int main(){
int dd; double tt;int cc;
m = 0; cin >> n;
while (n--){
cin >> dd >> cc >> tt;
if (tt < 38) continue;
++m;
a[m].date = dd;
a[m].code = cc;
a[m].tem = tt;
}
cout << m << '\n';
sort(a+1,a+m+1);
for (int i = 1; i <= m; ++i) a[i].print();
return 0;
}
把异常温度的都存起来,按要求排序就行
#include<bits/stdc++.h>
using namespace std;
struct A{
int t;
int num;
float te;
}a[110];
bool cmp(A b,A c){
if(b.t>c.t)return 1;
else if(b.t<c.t)return 0;
else{
if(b.te>c.te)return 1;
else if(b.te<c.te)return 0;
else{
if(b.num>c.num)return 0;
else
return 1;
}
}
}
int main(){
int n;
while(cin>>n){
int cnt=0;
while(n--){
int b,c;
float d;
cin>>b>>c>>d;
if(d>=38.0){
a[cnt].t=b;
a[cnt].num=c;
a[cnt].te=d;
cnt++;
}
}
cout<<cnt<<endl;
sort(a,a+cnt,cmp);
for(int i=0;i<cnt;i++){
printf("%d %d %.1f\n",a[i].t,a[i].num,a[i].te);
}
}
return 0;
}
快排函数+cmp bool真的之前没想到过要用,这次吃辣亏真的难受,以后记住啦;