Problem solution:
read the meaning of the problem well
1. Let event be a structure event
et: the time when events are accumulated together
er: the importance of the event (note, the importance as of the day i)
ed: the date of the start event
em: the month of the start event
e.id : sequence of events (index)
char name: event name
2. Input year to judge leap year
3. Input A to accumulate
4. Input sort to output D according to the meaning of the title * ****...
(peeked at other people's code for a long time ...)
~use vector<node(struct)>day[400]
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<vector>
#include<cmath>
using namespace std;
struct event
{
int t,r,d,m;//
int id;
char name[300];
bool operator<(const event &pos) const
{
if(t!=pos.t) return t<pos.t;
else if(r!=pos.r) return r>pos.r;
else return id<pos.id;
}
};
int time[]= {0,31,28,31,30,31,30,31,31,30,31,30,31};
vector<event> day[400];//每一天
int main()
{
int year,k=0;
bool flag=false;
scanf("%d",&year);
if(year%400==0||year%4==0&&year%100!=0)
time[2]=29;//是闰年
for(int i=2; i<=12; i++)
time[i]+=time[i-1];
while(1)
{
char ch[5];
char str[300];
cin>>ch;
if(ch[0]=='#') break;
else if(ch[0]=='A')
{
int d,m,p;
scanf("%d%d%d",&d,&m,&p);
gets(str);
while(str[0]==' ')//多余空格
for(int i=0; i<strlen(str); i++)
str[i]=str[i+1];
for(int i=max(1,time[m-1]+d-p); i<=time[m-1]+d; i++)
{
event tmp;
tmp.d=d;
tmp.m=m;
tmp.id=k;
strcpy(tmp.name,str);
if(i!=time[m-1]+d)//星号
tmp.r=p-(time[m-1]+d-i-1);
else
tmp.r=8;
tmp.t=time[m-1]+d;//
day[i].push_back(tmp);
}
for(int i=time[12]+time[m-1]+d-p; i<=time[12]; i++)
{
event tmp;
tmp.d=d;
tmp.m=m;
tmp.id=k;
strcpy(tmp.name,str);
tmp.r=p-(time[m-1]+d-1+time[12]-i);
tmp.t=time[m-1]+d+time[12];
day[i].push_back(tmp);
}
k++;
}
else if(ch[0]=='D')
{
//排序
if(!flag)
{
flag=true;
for(int i=0; i<=time[12]; i++)
sort(day[i].begin(),day[i].end());
}
int d,m;
scanf("%d%d",&d,&m);
printf("Today is:%3d%3d\n",d,m);
for(int i=0; i<day[time[m-1]+d].size(); i++)
{
printf("%3d%3d ",day[time[m-1]+d][i].d,day[time[m-1]+d][i].m);
if(day[time[m-1]+d][i].t==time[m-1]+d)
printf("*TODAY*");
else
{
for(int j=0; j<day[time[m-1]+d][i].r; j++)
printf("*");
for(int j=day[time[m-1]+d][i].r+1; j<8; j++)
printf(" ");
}
printf(" %s\n",day[time[m-1]+d][i].name);
}
printf("\n");
}
}
return 0;
}