当前位置:网站首页>PTA:7-64 该日是该年的第几天
PTA:7-64 该日是该年的第几天
2022-06-23 03:47:00 【Sy_Faker】
定义一个日期类Date,内有数据成员年、月、日,另有成员函数:构造函数用于初始化数据成员,输出,闰年的判断。 编写主函数:创建日期对象,计算并输出该日是该年的第几天。 输入格式: 测试输入包含若干测试用例,每个测试用例占一行。当读入0 0 0时输入结束,相应的结果不要输出。
输入样例:
2006 3 5
2000 3 5
0 0 0
输出样例:(括号内为说明)
64 (2006年3月5日是该年的第64天)
65 (2000年3月5日是该年的第65天)
#include<iostream>
using namespace std;
int A[12]={
31,29,31,30,31,30,31,31,30,31,30,31};
int B[12]={
31,28,31,30,31,30,31,31,30,31,30,31};
class Date
{
int year;
int month;
int day;
public:
Date(int y,int m,int d):year(y),month(m),day(d){
;}
void show()
{
if((year%4==0&&year%100!=0)||year%400==0)
{
for(int i=0;i<month-1;i++)
{
day+=A[i];
}
}
else
{
for(int i=0;i<month-1;i++)
{
day+=B[i];
}
}
cout<<day<<endl;
}
};
int main()
{
int a,b,c;
cin>>a>>b>>c;
while(a!=0&&b!=0&&c!=0)
{
Date d(a,b,c);
d.show();
cin>>a>>b>>c;
}
}
边栏推荐
猜你喜欢

redis 精讲系列介绍八 - 淘汰策略

深度学习 TensorFlow入门

Centos7 installing MySQL and configuring InnoDB_ ruby

京东云分布式数据库StarDB荣获中国信通院 “稳定性实践先锋”

Halcon胶线检测—模板匹配、位姿变换、胶宽,胶连续性检测

城链科技董事长肖金伟:践行数据经济系国家战略,引领数字时代新消费发展!

MySQL data recovery (.Ibdata1, bin log)

8 key indicators to measure technology debt in 2022

Photoshop PS viewing pixel coordinates, pixel colors, pixel HSB colors

x64dbg 基本使用技巧
随机推荐
Analysis on the current situation of the Internet of things in 2022
How to ensure application security
Flutter series: wrap in flutter
Software development in 2022: five realities CIOs should know
深度学习 简介
基于HAProxy实现网页动静分离
Pta:7-85 data spacing (overload + function template)
P1363 幻象迷宫(dfs)
Sequence table lookup
基于FPGA的VGA协议实现
Online JSON to CSharp (c) class tool
mysql存储引擎之Myisam和Innodb的区别
高效的远程办公经验 | 社区征文
flutter系列之:flutter中的Wrap
[tcapulusdb knowledge base] [list table] sample code of asynchronous scanning data
mysql如何删除表的一行数据
Section 2: spingboot unit test
APM 工具 SkyWalking 是什么
leetcode 91. Decode ways (medium)
Getting started with tensorflow