poj1209 uva 158 Calendar (模拟题)

这个题坑的不是一星半点,做了将近一天,多亏一个大佬给了组测试数据,但还要考虑很多
考虑12月到1月的情况
考虑如何排序,
考虑输出格式
考虑没星号要不要输出
考虑。。。。。。。。

我写的代码思想就是多存储了一个一月份。

我写的代码还是挺容易懂的挺短的,就是头文件多懒得删

符ac代码跟一组测试数据

#include<stdio.h>
#include<string.h>
#include<iostream>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<ctype.h>
#include<stack>
#include<math.h>
#include <string>
#include<algorithm>
#include <iterator>

using namespace std;

typedef unsigned long long ULL;

struct node
{
    int m;
    int d;
    int p;
    int id;
    int sum;
    char a[260];
}day;

int time[]={0,31,28,31,30,31,30,31,31,30,31,30,31},sum1;

bool cmp(const struct node& left,const struct node& right)
{
//    return left.sum==right.sum?left.p>right.p:left.sum<right.sum;

    if(left.sum==right.sum)
    {
        if(left.sum==sum1)
            return left.id<right.id;
        if(left.p==right.p)
            return left.id<right.id;
        else
            return left.p>right.p;
    }
    else
        return left.sum<right.sum;
}

int main()
{
    vector <struct node> days;
    int mark=0;
    int year;
    int m1,d1,i1=0;
    scanf("%d",&year);
    if(year%4==0)
        time[2]=29;
    for(int k=1;k<=12;k++)
        time[k]+=time[k-1];
    int i=0;
    char ch;
    int flag=0;
    while(1)
    {
        scanf("%c",&ch);
        if(ch=='#')
            break;
        if(ch=='A')
        {
            scanf("%d%d%d",&day.d,&day.m,&day.p);
            gets(day.a);
            while(day.a[0]==' ')
                for(int k=0;day.a[k];k++)
                    day.a[k]=day.a[k+1];
            day.sum=time[day.m-1]+day.d;
            if(day.m==1)
            {
                day.sum+=time[12];
                mark=1;
            }
            day.id=i;
            days.push_back(day);
            if(mark==1)
            {
                day.sum-=time[12];
                mark=0;
                days.push_back(day);
                i1++;
            }
            i++;
        }
        if(ch=='D')
        {
            scanf("%d%d",&d1,&m1);
            sum1=time[m1-1]+d1;
            sort(days.begin(),days.end(),cmp);
            flag=1;
            printf("Today is:%3d%3d\n",d1,m1);
            for(int j=0;j<i+i1;j++)
            {
                if(sum1>days[j].sum)
                    continue;
                if(sum1==days[j].sum)
                    printf("%3d%3d *TODAY* %s\n",days[j].d,days[j].m,days[j].a);
                else
                {

                    int k=days[j].p-(days[j].sum-sum1)+1;
                    int k1=7-k;
                    if(k<=0)
                        continue;
                    printf("%3d%3d ",days[j].d,days[j].m);
                    while(k--)
                        printf("*");
                    while(k1--)
                        printf(" ");
                    printf(" %s\n",days[j].a);
                }
            }
            printf("\n");
        }
    }
    return 0;
}
1980
A 23 12 5 Partner's birthday
A 25 12 7 Christmas
A 20 12 1 Unspecified Anniversary
A 25 12 7 Christmas So Important
A 26 12 6 Boxing Day
A 26 12 6 Christmas Eve + 2
A 1 1 6 New Year
A 31 12 6 New Year Eve
A 1 1 7 New Year Again
A 2 1 4 Nothing
A 1 3 4 First Day of March
A 28 2 4 Feb Regular
A 29 1 2 WAHAHA
A 1 2 4 AWA
D 26 2
D 27 2
D 28 2
D 1 3
D 2 3
D 3 3
D 20 12
D 21 12
D 22 12
D 23 12
D 24 12
D 25 12
D 26 12
D 27 12
D 28 12
D 29 12
D 30 12
D 31 12
D 1 1
D 1 2
D 28 1
#
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值