Openjudge-计算概论(A)-判断闰年

描述:

判断某年是否是闰年。输入输入只有一行,包含一个整数a(0 < a < 3000)输出一行,如果公元a年是闰年输出Y,否则输出N样例输入

2006

样例输出

N

提示:公历纪年法中,能被4整除的大多是闰年,但能被100整除而不能被400整除的年份不是闰年, 能被3200整除的也不是闰年,如1900年是平年,2000年是闰年,3200年不是闰年。

思路:入门题之一,两个判断即可,如果a能整除4并且能整除100,是!或者能整除400,是!,否则不是!

代码如下:

#include<stdio.h>
int main()
{
  int a;
  scanf("%d",&a);
  if((a%4==0&&a%100!=0)||a%400==0)
  {
      printf("Y");
  }
  else
  {
      printf("N");
  }
  return 0;
}
时间: 2025-01-02 18:50:34

Openjudge-计算概论(A)-判断闰年的相关文章

计算概论(A)/基础编程练习2(8题)/5:点和正方形的关系

1 #include<stdio.h> 2 #include<math.h> 3 int main() { 4 // 输入坐标 5 float x, y; 6 while(scanf("%f %f", &x, &y) != EOF) { 7 // 计算坐标点与原点的欧氏距离 8 float dist=sqrt(x*x+y*y); 9 10 /* 11 // 简单判断横坐标和纵坐标的截距abs(x).abs(y)和与原点距离dist 注意:abs(

计算概论(A)/基础编程练习2(8题)/7:整数的个数

1 #include<stdio.h> 2 int main() { 3 int k,temp,n[3] = {0}; 4 5 // 输入k个正整数 6 scanf("%d",&k); 7 8 // 循环读入和进行算术 9 while(scanf("%d",&temp)!=EOF) { 10 switch(temp) { 11 case 1: 12 n[0]++; 13 break; 14 case 5: 15 n[1]++; 16 br

Js获取当前日期时间+日期印证+判断闰年+日期的天数差+日期格式化+JS判断某年某月有多少天

Js获取当前日期时间+日期验证+判断闰年+日期的天数差+日期格式化+JS判断某年某月有多少天 字符串转日期型+Js当前日期时间+日期验证+判断闰年+日期的天数差+日期格式化+日期所在年的第几周 日期时间脚本库方法列表Date.prototype.isLeapYear 判断闰年Date.prototype.Format 日期格式化Date.prototype.DateAdd 日期计算Date.prototype.DateDiff 比较日期差Date.prototype.toString 日期转字符

JavaScript判断闰年

<html><head>   <meta http-equiv="content-type" content="text/html;charset=gb2312">   <title>判断闰年_www.jbxue.com</title>   <script type="text/javascript" languge="javascript">    //

计算概论(A)/基础编程练习2(8题)/1:求平均年龄

1 #include<stdio.h> 2 int main() { 3 // 声明与初始化 4 int n, count=1, s=0, age=0; 5 6 // 输入学生人数 7 scanf("%d", &n); 8 9 // 循环读入 加和 10 while(count<=n) { 11 scanf("%d",&age); 12 s+=age; 13 count++; 14 } 15 16 // 计算平均年龄输出 17 pr

计算概论(A)/基础编程练习(数据成分)/1:短信计费

1 #include<stdio.h> 2 int main() { 3 // 输入当月发送短信的总次数n和每次短信的字数words 4 int n,words; 5 scanf("%d",&n); 6 float price=0.0; 7 8 while(scanf("%d",&words)!=EOF) { 9 // 所发送的短信超过了70个字,则会按照每70个字一条短信的限制把它分割成多条短信发送 10 price+=(words%7

计算概论(A)/基础编程练习1(8题):1:大象喝水

计算概论(A)/基础编程练习1(8题)/1:大象喝水 地址:http://pkuic.openjudge.cn/base1/1/ 1 #include<stdio.h> 2 int main() { 3 /* 圆周率常数 */ 4 const float Pi = 3.14159; 5 6 /* 深h厘米 半径r厘米 均为整数 */ 7 int h, r; 8 scanf("%d %d", &h, &r); 9 10 /* 一桶水的升数 1升 = 1000毫

【北大先修课】计算概论(A)题库全代码

题目很水就是全都是坑真是丧心病狂啊 把代码留下造福后来人QωQ 结构体与链表练习 生日相同2.0 #include<iostream> #include<cstdio> #include<cstring> #include<cmath> #include<algorithm> #define MAXN 200 using namespace std; struct st { int m,d; string name; bool operator&

c判断闰年

编写程序判断输入的年份是闰年还是平年. 闰年的判断准则是:1.能被4整除且不能被100整除的为闰年,2.或者是能被400整除. 代码如下: 1 //判断闰年 2 #include<iostream> 3 using namespace std; 4 5 int main() 6 { 7 int year; 8 cout << "输入年份" << endl; //输入需判断的年份 9 cin >> year; 10 if (year % 4

if语句判断闰年、平年

 一.让用户输入一个年份,判断是否是闰年. 判断一个年份是否是闰年有两个条件 ①能被400整除:②能被4整除但是不能被100整除 Console.WriteLine("请输入年份:"); int nian = Convert.ToInt32(Console.ReadLine()); Console.WriteLine("请输入月份:"); int yue = Convert.ToInt32(Console.ReadLine()); Console.WriteLine