前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >ACMSGURU 115 - Calendar

ACMSGURU 115 - Calendar

作者头像
Reck Zhang
发布2021-08-11 10:55:25
5660
发布2021-08-11 10:55:25
举报
文章被收录于专栏:Reck Zhang

Calendar

Problem Description

First year of new millenium is gone away. In commemoration of it write a program that finds the name of the day of the week for any date in 2001.

Input

Input is a line with two positive integer numbers N and M, where N is a day number in month M. N and M is not more than 100.

Output

Write current number of the day of the week for given date (Monday – number 1, … , Sunday – number 7) or phrase “Impossible” if such date does not exist.

Sample Input

21 10

Sample Output

7

Solution

代码语言:javascript
复制
#include <bits/stdc++.h>

int main() {

    std::ios::sync_with_stdio(false);

    std::vector<int> month{31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};

    int n, m;
    std::cin >> n >> m;
    if(m > 12 || n > month[m - 1]) {
        std::cout << "Impossible";
    }

    int day = 0;
    for(int i = 0; i < m - 1; i++) {
        day += month[i];
    }
    day += n - 1;

    std::cout << day % 7 + 1 << std::endl;
}
本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2019-12-10,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • Calendar
    • Problem Description
      • Input
        • Output
          • Sample Input
            • Sample Output
              • Solution
              领券
              问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档