北大2894

来源:互联网 发布:穿越之一叶而知秋 编辑:程序博客网 时间:2024/04/29 08:48

 题目链接:http://acm.pku.edu.cn/JudgeOnline/problem?id=2894

这里主要用到了对象的生命期的概念,这个概念其实来源于网络的学习,为每个对象赋予一个出生日期和死亡日期,然后在最早出生日期和最晚出生日期之间进行模拟。

 

#include <iostream>
using namespace std;

struct Exist
{
 char data;
 int begin;
 int end;
};

int main()
{
 freopen("in.txt","r",stdin);

 Exist exist[26];
 int i,j,t,n,begin,end,index;

 while(cin >> t)
 {
  while(t--)
  {
   cin >> n;
   for(i = 0;i < n;++i)
    cin >> exist[i].data >> exist[i].begin >> exist[i].end;

   begin = 1000,end = 0;
   for(i = 0;i < n;++i)
   {
    if(exist[i].end > end)
     end = exist[i].end;
    if(exist[i].begin < begin)
     begin = exist[i].begin;
   }

   for(i = begin;i <= end;++i)
   {
    index = 0;
    for(j = 0;j < n;++j)
    {
     if(exist[j].begin <= i && exist[j].begin != exist[j].end)
     {
      ++index;
      ++exist[j].begin;
     }
    }
    if(index != 0)
     cout << char('A' + index - 1);
   }
   cout << endl;
  }
 }
 return 0;
}

原创粉丝点击