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

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

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

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

顺序输出课程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 5ip

输出样例:字符串

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
ZOE1string

思路it

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

而后 由于数据量大 不能用STRING 也就是 不能用 CIN 输入 会超时class

而后 能够用 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\n", 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\n", (*it).a[0], (*it).a[1], (*it).a[2], (*it).a[3]);
        }
    }
}
相关文章
相关标签/搜索