1 solutions
-
0
C :
#include<stdio.h> int fun(int y,int m,int d); int isrunnian(int n) { if(n%4 == 0&&n%100 != 0 || n%400 == 0) return 1; else return 0; } int main() { int t,y,m,d; int allday; scanf("%d",&t); while(t--) { scanf("%d%d%d",&y,&m,&d); allday = fun(y,m,d); printf("%d年%d月%d日是星期",y,m,d); if(y > 1979) switch(allday%7) { case 0:printf("一");break; case 1:printf("二");break; case 2:printf("三");break; case 3:printf("四");break; case 4:printf("五");break; case 5:printf("六");break; case 6:printf("日");break; } else switch(allday%7) { case 0:printf("一");break; case 1:printf("日");break; case 2:printf("六");break; case 3:printf("五");break; case 4:printf("四");break; case 5:printf("三");break; case 6:printf("二");break; } printf("\n"); } return 0; } int fun(int y,int m,int d) { int i,dy,allday = 0; int a[12]={31,29,31,30,31,30,31,31,30,31,30,31}; int b[12]={31,28,31,30,31,30,31,31,30,31,30,31}; if(y > 1979) { dy = 1980; while(dy < y) { if(isrunnian(dy)) allday += 366; else allday += 365; dy++; } if(isrunnian(y)) for(i = 0;i < m - 1;i++) allday += a[i]; else for(i = 0;i < m - 1;i++) allday += b[i]; allday += d; } else { dy = 1979; while(dy > y) { if(isrunnian(dy)) allday += 366; else allday += 365; dy--; } if(isrunnian(y)) for(i = 11;i >= m;i--) allday += a[i]; else for(i = 11;i >= m;i--) allday += b[i]; allday += (a[m-1]-d); if(isrunnian(y)&&m == 2) allday--; } return allday; }C++ :
#include<iostream> #include<cstdio> using namespace std; int main() { //freopen("1.txt","r",stdin); //freopen("2.txt","w",stdout); int year,month,day; int M; cin >> M; while(M--) { cin >> year >> month >> day; // 输入年月日 bool leap = year%400 == 0 || year%100 != 0 && year%4 == 0; // 判断闰年 int total = year-1980+(year-1980+3)/4; // 求平(闰)年累计的总天数 for(int i = month-1; i > 0; i--) { switch(i) { case 1:case 3:case 5:case 7:case 8:case 10:total += 31; break; case 4:case 6:case 9:case 11:total += 30; break; case 2:total += leap ? 29 : 28; } } total += day; // 当个月的天数 int week = 1; // 起始日是1979-12-31是星期一 week = (week+total)%7; // 求得星期几 cout << year << "年" << month << "月" << day << "日" << "是星期"; switch(week) { case 0:cout << "日" << endl; break; case 1:cout << "一" << endl; break; case 2:cout << "二" << endl; break; case 3:cout << "三" << endl; break; case 4:cout << "四" << endl; break; case 5:cout << "五" << endl; break; case 6:cout << "六" << endl; break; } } return 0; }
- 1
Information
- ID
- 18467
- Time
- 1000ms
- Memory
- 128MiB
- Difficulty
- (None)
- Tags
- (None)
- # Submissions
- 0
- Accepted
- 0
- Uploaded By