SGU115 水题 Too Easy

来源:互联网 发布:图灵丛书 数据库 编辑:程序博客网 时间:2024/04/30 10:49

Problem: Write a program that finds the name of the day of the week for any date in 2001(Monday – number 1, … , Sunday – number 7).

Solution: "Impossible" is important...

#include <stdio.h>#include <iostream>using namespace std;int p[13] = {0,31,28,31,30,31,30,31,31,30,31,30,31};int n,m,sum;int main() {    while (~scanf("%d%d",&n,&m)) {          sum = 0;          if (m<1 || m>12 || n<1 || n>p[m]) {             printf("Impossible\n");             continue;          }          int tt = 1;          while (tt<m) {                sum += p[tt];                tt++;          }          sum += n;          sum %= 7;          if (sum==0) sum = 7;          printf("%d\n",sum);    }    return 0;}


0 0
原创粉丝点击