POJ 2080(calender)

简介: 大致题意:给出自从2000 1 1过的天数,以-1结束,输出日期和星期 //以后遇到闰年的问题,坚决用二维数组 #include #include #define N 10010 char date[7][10]={"Sunday","Monday","Tuesday","Wedne...

大致题意:给出自从2000 1 1过的天数,以-1结束,输出日期和星期

//以后遇到闰年的问题,坚决用二维数组 
#include<stdio.h>
#include<string.h>
#define N 10010
char date[7][10]={"Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"};
int vis[2][12]={31,28,31,30,31,30,31,31,30,31,30,31,31,29,31,30,31,30,31,31,30,31,30,31}; //vis[0]表示非闰
int leap[N];
void isleap()
{
    int i,j;
    memset(leap,0,sizeof(leap));
    for(i=2000;i<N;i++)
    if(i%4==0&&i%100!=0||i%400==0)
        leap[i]=1;
}
int main()
{
    int i,j,k;
    int num;
    int flag;//星期代表元 
    int year;
    isleap();
    while(scanf("%d",&num),num!=-1)
    {
        k=num;
        flag=(num+6)%7;//第一天星期6,先求flag是因为,后来num要改变 
        for(i=2000;num>=(leap[i]==1?366:365);i++)//第一次判断便不成立时,i没有自增,以后就自增了 
        {
            if(leap[i])
                num-=366;
            else
                num-=365;
        }
       // printf("i=%d\n",i);
        for(j=0;num>=vis[leap[i]][j]&&j<12;j++)//月份
        {
            num-=vis[leap[i]][j];
        }
        printf("%d-%02d-%02d %s\n",i,j+1,num+1,date[flag]);//注意6要输出为06 
    }
    return 0;
}
        
       
        
        
        
        
        
        
         
            
                
            
        
    
    

 

目录
相关文章
|
算法框架/工具
POJ 2262 Goldbach's Conjecture
POJ 2262 Goldbach's Conjecture
115 0
POJ 2027 No Brainer
POJ 2027 No Brainer
82 0
|
人工智能 算法 BI
poj 2192 Zipper
题目链接:http://poj.org/problem?id=2192 Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 18658   Accepted: 6651 Description Given ...
953 0
POJ 1012 Joseph
Joseph Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 53862   Accepted: 20551 Description The Joseph's problem is notoriously known.
817 0
|
人工智能
POJ 2531
初学dfs参考别人代码,如有雷同,见怪不怪。#include using namespace std; int aa[25][25]; int maxa=0; int step[25]={0},n; void dfs(int a,int b) { int t=b; step...
676 0
poj-3094-quicksum
http://poj.org/problem?id=3094 很简单 #include #include using namespace std; int main() { string a; int sum=0; while(getline(cin...
552 0
|
并行计算 网络架构
poj-1005-l tanink i need a houseboat
Description Fred Mapper is considering purchasing some land in Louisiana to build his house on. In the process of investigating the land, he learned ...
938 0
POJ 2487 Stamps
Description Background Everybody hates Raymond. He’s the largest stamp collector on planet earth and because of that he always makes fun of all the others at the stamp collector parties.
1035 0
POJ 2262 Goldbach&#39;s Conjecture
Problem Description In 1742, Christian Goldbach, a German amateur mathematician, sent a letter to Leonhard Euler in which he made the foll...
968 0