DESCRIPTION: 大意是说 先给你n个 同学的 上课时间。一周的第几天,开始和结束的时间点。然后对应q个出去玩的时间。要你给出谁不能出去。如果都能出去就输出none。

开始做的时候觉得每个同学的上课信息太多了。还要更新。不知道用什么方法存储。看题解,居然是二维数组8*12....好机智的说....

附代码:
#include<stdio.h>
#include<iostream>
#include<string.h>
#include<string>
#include<algorithm>
using namespace std;

struct Lesson
{
    string name;
    int time[8][12];   //以数组里的数字是1还是0来保存 这个时刻是不是有空。
}lesson[225];

int main()
{
    int t, n;
    cin >> t;
    while(t--)
    {
        cin >> n;
        for (int i=0; i<225; ++i)
        {
            memset(lesson[i].time, 0, sizeof(lesson[i].time));
        }
        for (int i=0; i<n; ++i)              
        {
            int k;
            cin >> lesson[i].name >> k;
            for (int j=0; j<k; ++j)
            {
                int d, b, e;
                cin >> d >> b >> e;
                for (int kk=b; kk<=e; ++kk)
                {
                    lesson[i].time[d][kk] = 1;
                }
            }
        }
        int q;
        cin >> q;
        string name[225];
        for (int i=0; i<q; ++i)
        {
            int cnt = 0;
            int d, b, e;
            cin >> d >> b >> e;
            for (int j=0; j<n; ++j)
            {
                for (int kk=b; kk<=e; ++kk)
                {
                    if (lesson[j].time[d][kk] == 1)
                    {
                        name[cnt++] = lesson[j].name;
                        break;
                    }
                }
            }
            if (cnt == 0)
            {
                cout << "None\n";
                continue;
            }
            sort(name, name+cnt);
            for (int j=0; j<cnt; ++j)
            {
                 if (j == 0)
                    cout << name[j];
                 else cout << ' ' << name[j];
            }
            cout << endl;
        }
    }
    return 0;
}

posted on 2015-07-23 23:13  小小八  阅读(280)  评论(0编辑  收藏  举报