1062. Talent and Virtue (25) 大量输入输出 scanf printf会比cin cout 省很多时间

简介: #include #include #include using namespace std;struct node{ int id, v, t, g;};vector v[4];int cmp(node &a, node &b) { if (a.
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

struct node{
    int id, v, t, g;
};
vector<node> v[4];

int cmp(node &a, node &b) {
    if (a.g != b.g)
        return a.g > b.g;
    else if (a.v != b.v)
        return a.v > b.v;
    else
        return a.id < b.id;
}
void Sort(vector<node> &a){ sort(a.begin(), a.end(), cmp); }
void print(vector<node> &a){
    Sort(a);
    for (int i = 0; i < a.size(); i++)
        printf("%d %d %d\n", a[i].id, a[i].v, a[i].t);
}

int main() {
    int n, l, h, cnt;
    cin >> n >> l >> h;
    cnt = n;
    for (int i = 0; i < n; i++) {
        int id, vi, t;
        scanf("%d %d %d", &id, &vi, &t);
        if (vi >= l && t >= l){
            node temp{id, vi, t, vi+t};
            if(vi >= h && t >= h) v[0].push_back(temp);
            else if(vi >= h && t < h) v[1].push_back(temp);
            else if(vi < h && t < h && vi >= t) v[2].push_back(temp);
            else v[3].push_back(temp);
        }else cnt--;
    }
    cout << cnt << endl;
    for (int i = 0; i < 4; i++) print(v[i]);
    return 0;
}

目录
相关文章
|
1月前
|
C语言
你真的学会了printf和scanf函数吗?
你真的学会了printf和scanf函数吗?
|
3月前
cout,printf的++,--优先问题
cout,printf的++,--优先问题
13 0
|
21天前
|
存储 C语言
用scanf函数输入数据
用scanf函数输入数据
9 1
|
4月前
c中scanf函数注意点
c中scanf函数注意点
30 0
|
4月前
|
缓存
scanf和printf函数
scanf和printf函数
57 0
|
6月前
|
缓存 C++
C++的输入与输出:cin与cout
C++的输入与输出:cin与cout
|
9月前
|
存储 Serverless C语言
printf()和scanf() (详解)
printf()和scanf() (详解)
|
10月前
|
C++
C++(cout和printf的使用小结)
C++(cout和printf的使用小结)
|
算法 C++ iOS开发