SGU - 115 - Calendar (基础题!)

SGU - 115

Calendar

Time Limit: 250MS   Memory Limit: 4096KB   64bit IO Format: %I64d & %I64u

Submit Status

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 MN 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

Author : Michael R. Mirzayanov
Resource : PhTL #1 Training Contests
Date : January 2002

Source

看起来挺简单的一个题。。

但是我WA了3次,,哭%>_<%啊

要判断日期是否合法,不合法则输出Impossible,合法则输出所对应的星期几,而2001年第一天就是星期一,模7即可。。

AC代码:

#include <cstdio>
#include <cstring>
#include <algorithm>
#include <iostream>
#include <cmath>
using namespace std;

int a[13] = {0,31,28,31,30,31,30,31,31,30,31,30,31};

int judge(int n, int m)     //判断日期是否合法
{
	if(n==1 || n==3 || n==5 || n==7 || n==8 || n==10 || n==12)
	{
		if(m<=31)return 0;
	}
	else if(n==4 || n==6 || n==9 || n==11)
	{
		if(m<=30)return 0;
	}
	else if(n==2)
	{
		if(m<=28)return 0;
	}
	else return 1;
}

int main()
{
	int n, m;
	int flag = 0, ans = 0;
	scanf("%d %d", &n, &m);
	if(judge(m, n))flag = 1;
	else
	{
		for(int i=1; i<m; i++)
		{
			ans += a[i];
		}
		ans += n;
	}
	if(flag)
	{
		printf("Impossible\n");
	}
	else
	{
		ans %= 7;
		if(ans == 0) ans = 7;
		printf("%d\n", ans);
	}
	return 0;
} 
时间: 2024-08-24 09:49:41

SGU - 115 - Calendar (基础题!)的相关文章

SGU[115] Calendar

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. 千禧年过后的第一年已经过去了.为了纪念它,请你写一个程序来计算2001年中任何一天的星期. Input 输入 Input is a line with two positive

HDU 2966 Aragorn&#39;s Story 树链剖分第一题 基础题

Problem Description Our protagonist is the handsome human prince Aragorn comes from The Lord of the Rings. One day Aragorn finds a lot of enemies who want to invade his kingdom. As Aragorn knows, the enemy has N camps out of his kingdom and M edges c

SGU 115

水题,调用蔡勒公式即可解决.(由于年份限定为2001,所以模拟似也可以解决) 注意判定数据的合法性. 另外,根据题目要求,出现负数或零的数据也是符合题目条件的,但似乎SGU并没有这么做- - #include "stdio.h" int main(){ int maxday[13]={0,31,28,31,30,31,30,31,31,30,31,30,31}; int Y=1,C=20; int M,D,day; scanf("%d%d",&D,&

面试题收集-java面试题及答案(基础题122道,代码题19道)

JAVA相关基础知识1.面向对象的特征有哪些方面?1.抽象:抽象就是忽略一个主题中与当前目标无关的那些方面,以便更充分地注意与当前目标有关的方面.抽象并不打算了解全部问题,而只是选择其中的一部分,暂时不用部分细节.抽象包括两个方面,一是过程抽象,二是数据抽象.2.继承:继承是一种联结类的层次模型,并且允许和鼓励类的重用,它提供了一种明确表述共性的方法.对象的一个新类可以从现有的类中派生,这个过程称为类继承.新类继承了原始类的特性,新类称为原始类的派生类(子类),而原始类称为新类的基类(父类).派

python每日经典算法题5(基础题)+1(中难题)

现在,越来越多的公司面试以及考验面试对算法要求都提高了一个层次,从现在,我讲每日抽出时间进行5+1算法题讲解,5是指基础题,1是指1道中等偏难.希望能够让大家熟练掌握python的语法结构已经一些高级函数的应用.这些题目是在某些刷题的网站上登记的有水平的题目.这里如果有需要input的简单题,就略去了输出结果.如果时间充裕,则就会增加每日更多习题. 一:基础算法题10道 1.判断用户输入的年份是否为闰年 题目解析: (1)问题分析:能被4整除但不能被100整除的年份为普通闰年,能被400整除的年

1、基础题

基础题: 1.表单中 get与post提交方法的区别? 答:get是发送请求HTTP协议通过url参数传递进行接收,而post是实体数据,可以通过表单提交大量信息. 2.session与cookie的区别? 答:session:储存用户访问的全局唯一变量,存储在服务器上的php指定的目录中的(session_dir)的位置进行的存放 cookie:用来存储连续訪問一个頁面时所使用,是存储在客户端,对于Cookie来说是存储在用户WIN的Temp目录中的. 两者都可通过时间来设置时间长短 3.数据

【HDU1232】畅通工程(并查集基础题)

裸敲并查集,很水一次AC 1 #include <iostream> 2 #include <cstring> 3 #include <cstdlib> 4 #include <cstdio> 5 #include <cctype> 6 #include <cmath> 7 #include <algorithm> 8 #include <numeric> 9 #include <string> 1

linux 基础题整理

基础题: 1.查看系统内核版本号及系统名称 2.查看smb服务所用的端口号 3.禁ping 4.查出22端口现在运行什么程序 5.登录提示符前的输出信息"you are welcome!!!" 6.成功登录后自动输出信息"距离全国比赛还剩1天!!!" 7.确认安全终端为tty1 8.取消普通用户的控制台访问的三个权限:reboot.halt.shutdown 9.只允许组ID为10的成员通过su命令改变为root用户 10.禁止Control-Alt-Delete键

一些DP基础题(1)

HDU 1024  Max Sum Plus Plus Now I think you have got an AC in Ignatius.L's "Max Sum" problem. To be a brave ACMer, we always challenge ourselves to more difficult problems. Now you are faced with a more difficult problem. Given a consecutive num