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;
}

目录
相关文章
|
10月前
|
C语言
你真的学会了printf和scanf函数吗?
你真的学会了printf和scanf函数吗?
|
10月前
cout,printf的++,--优先问题
cout,printf的++,--优先问题
49 0
|
10月前
|
编译器 C语言 C++
scanf函数
该文介绍了C语言中`scanf`函数用于输入变量值,而`printf`函数用于输出变量值。`scanf`在读取数值时会自动过滤空白字符,允许数据间有空格或换行,不影响解析。`scanf`返回值表示成功读取的变量数,0表示未读取或匹配失败,EOF表示读取错误或文件结尾。常见占位符包括 `%c`(字符)、`%d`(整数)、`%f`(浮点数)、`%s`(字符串)和`%[]`(指定字符集)。对于`%c`,不会忽略空白字符,但可加空格跳过前导空白。文章还提及在VS2022中,`scanf`被认为是不安全的,推荐使用`scanf_s`,并提供了如何在VS中使用`scanf`的解决方法。
169 1
|
10月前
|
C语言
1.printf()2.scanf()
1.printf()2.scanf()
50 0
c中scanf函数注意点
c中scanf函数注意点
98 0
|
缓存
scanf和printf函数
scanf和printf函数
174 0
|
C语言
printf与scanf函数的返回值
printf与scanf函数的返回值
C++的输入与输出:cin与cout
C++的输入与输出:cin与cout
|
存储 Serverless C语言
printf()和scanf() (详解)
printf()和scanf() (详解)
215 0
C++(cout和printf的使用小结)
C++(cout和printf的使用小结)