zoukankan      html  css  js  c++  java
  • 7-5 打印选课学生名单(25 point(s)) 【排序】

    7-5 打印选课学生名单(25 point(s))

    假设全校有最多40000名学生和最多2500门课程。现给出每个学生的选课清单,要求输出每门课的选课学生名单。
    输入格式:

    输入的第一行是两个正整数:N(≤40000),为全校学生总数;K(≤2500),为总课程数。此后N行,每行包括一个学生姓名(3个大写英文字母+1位数字)、一个正整数C(≤20)代表该生所选的课程门数、随后是C个课程编号。简单起见,课程从1到K编号。
    输出格式:

    顺序输出课程1到K的选课学生名单。格式为:对每一门课,首先在一行中输出课程编号和选课学生总数(之间用空格分隔),之后在第二行按字典序输出学生名单,每个学生名字占一行。
    输入样例:

    10 5
    ZOE1 2 4 5
    ANN0 3 5 2 1
    BOB5 5 3 4 2 1 5
    JOE4 1 2
    JAY9 4 1 2 5 4
    FRA8 3 4 2 5
    DON2 2 4 5
    AMY7 1 5
    KAT3 3 5 4 2
    LOR6 4 2 4 1 5

    输出样例:

    1 4
    ANN0
    BOB5
    JAY9
    LOR6
    2 7
    ANN0
    BOB5
    FRA8
    JAY9
    JOE4
    KAT3
    LOR6
    3 1
    BOB5
    4 7
    BOB5
    DON2
    FRA8
    JAY9
    KAT3
    LOR6
    ZOE1
    5 9
    AMY7
    ANN0
    BOB5
    DON2
    FRA8
    JAY9
    KAT3
    LOR6
    ZOE1

    思路

    可以用VECTOR 来保存 每门课下 的学生名字
    然后输出的时候 对每门课 对应的那个 VECTOR 进行排序就可以了

    然后 因为数据量大 不能用STRING 也就是 不能用 CIN 输入 会超时

    然后 可以用 C风格字符串

    然后一种思路就是

    因为学生姓名 的格式 是固定的

    3个大写英文字母+1位数字
    所以 我们可以将三个大写英文字母对应的 ASCII 码 保存下来 形成一串数字

    比如 AAA1

    就对应于 65656501

    这串数字 就对应 于 这个 姓名
    并且 可以进行比较

    输出的时候 输出其对应的字母就可以了

    AC代码

    #include <cstdio>
    #include <cstring>
    #include <ctype.h>
    #include <cstdlib>
    #include <cmath>
    #include <climits>
    #include <ctime>
    #include <iostream>
    #include <algorithm>
    #include <deque>
    #include <vector>
    #include <queue>
    #include <string>
    #include <map>
    #include <stack>
    #include <set>
    #include <numeric>
    #include <sstream>
    #include <iomanip>
    #include <limits>
    
    #define CLR(a) memset(a, 0, sizeof(a))
    #define pb push_back
    
    using namespace std;
    typedef long long ll;
    typedef long double ld;
    typedef unsigned long long ull;
    typedef pair <int, int> pii;
    typedef pair <ll, ll> pll;
    typedef pair<string, int> psi;
    typedef pair<string, string> pss;
    
    const double PI = 3.14159265358979323846264338327;
    const double E = exp(1);
    const double eps = 1e-30;
    
    const int INF = 0x3f3f3f3f;
    const int maxn = 3e3 + 5;
    const int MOD = 1e9 + 7;
    
    struct Node
    {
        int a[4];
        int name;
    }temp;
    
    vector <Node> ans[maxn];
    
    bool comp(Node x, Node y)
    {
        return x.name < y.name;
    }
    
    
    int main()
    {
        int n, k;
        scanf("%d%d ", &n, &k);
        char a[3];
        int b;
        int tot, id;
        int name;
        string s;
        for (int i = 0; i < n; i++)
        {
            scanf(" %c %c %c %d", &temp.a[0], &temp.a[1], &temp.a[2], &temp.a[3]);
            temp.name = 0;
            for (int i = 0; i < 4; i++)
                temp.name = temp.name * 100 + temp.a[i];
            scanf("%d", &tot);
            for (int j = 0; j < tot; j++)
            {
                scanf("%d", &id);
                ans[id].pb(temp);
            }
        }
        for (int i = 1; i <= k; i++)
        {
            printf("%d %d
    ", i, ans[i].size());
            if (ans[i].size())
            {
                sort(ans[i].begin(), ans[i].end(), comp);
                vector <Node>::iterator it;
                for (it = ans[i].begin(); it != ans[i].end(); it++)
                    printf("%c%c%c%d
    ", (*it).a[0], (*it).a[1], (*it).a[2], (*it).a[3]);
            }
        }
    }
    
    
    
    
    
    
    
  • 相关阅读:
    高性能 HTML5 地铁样式的应用程序中的内容
    微软披露更多ARM Win8细节
    下一代互联网搜索的前沿:意图、知识与云
    使用 Sphinx 更好地进行 MySQL 搜索使用 Sphinx 进行非全文本搜索
    如何加快数模计算以及如何解决数模计算的收敛性问题
    Google App Engine正式支持Python 2.7
    ASP.NET MVC模型绑定
    给 MySQL 增加 Sequence 管理功能
    使用 Rational Build Forge 自动化 IBM Cloud 上的构建和发布过程
    Windows Phone 8基于WinRT?
  • 原文地址:https://www.cnblogs.com/Dup4/p/9433182.html
Copyright © 2011-2022 走看看