SGU115 水题 Too Easy

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;
}


SGU115 水题 Too Easy

上一篇:LeetCode OJ:Unique Paths II


下一篇:迟到的2013年总结