poj1426,POJ1209 UVA158 Calendar題解

 2023-11-18 阅读 31 评论 0

摘要:代碼來源:DeathYmz AC的C++語言程序如下: #include<iostream> #include<cstring> #include<cstdio> #include<algorithm> #include<vector> #include<cmath> using namespace std; struct event{int t,r,d,m;//int

代碼來源:DeathYmz


AC的C++語言程序如下:

#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%4==0) time[2]=29;//是閏年 for(int i=2;i<=12;i++)time[i]+=time[i-1];while(1){char ch[5];char str[300];//scanf("%s",&ch);cin>>ch;if(ch[0]=='#') break;else if(ch[0]=='A'){//flag=false;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);elsetmp.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;
}


poj1426?

版权声明:本站所有资料均为网友推荐收集整理而来,仅供学习和研究交流使用。

原文链接:https://hbdhgg.com/4/175956.html

发表评论:

本站为非赢利网站,部分文章来源或改编自互联网及其他公众平台,主要目的在于分享信息,版权归原作者所有,内容仅供读者参考,如有侵权请联系我们删除!

Copyright © 2022 匯編語言學習筆記 Inc. 保留所有权利。

底部版权信息