当前位置: 首页 > news >正文

济南定制网站制作公司做网站专题页需要注意什么

济南定制网站制作公司,做网站专题页需要注意什么,用jsp实现网站开发的流程,哪个网站做简历比较好编程题: 题一:计算日期到天数的转换 计算日期到天数转换_牛客题霸_牛客网 (nowcoder.com) 示例1 输入: 2012 12 31 输出: 366 思路一: 第一步:创建年,月,日的变量,并按…

编程题:

题一:计算日期到天数的转换

计算日期到天数转换_牛客题霸_牛客网 (nowcoder.com)

示例1

输入:

2012 12 31

输出:

366

思路一:

第一步:创建年,月,日的变量,并按要求输入;

第二步:创建一个数组记录平年每个月的天数,以及记录总天数的sum;

第三步:将除当前月的以外的天数记录在sum中,再去判断是不是闰年,是就+1;

第四步:打印总天数。

#include <iostream>
using namespace std;int main() 
{int _year,_month,_day;cin>>_year>>_month>>_day;int sum = _day;int arr[13] = {0,31,28,31,30,31,30,31,31,30,31,30,31};int n = _month;while(--n){sum += arr[n];}if(_month > 2 && ((_year % 4 == 0 && _year % 100 != 0) || (_year % 400 == 0)))sum += 1;cout<<sum<<endl;return 0;
}

思路二:

第一步:创建一个日期类:私有成员变量有:年,月,日;

第二步:创建一个构造函数,给自定义类型的对象完成初始化;创建一个赋值运算符重载" >> "保证自定义类型的输入;以及赋值运算符重载" << "自定义保证能够输出自定义类型的内容;需要注意的是" << " " >> "需要声明为友元函数,且在类外定义;最后再创建一个函数得到当前年这个月的天数;

第三步:根据题意将输入的年,月,日转换成是这一年的第几天;

#include <iostream>
using namespace std;class Date
{public://构造函数Date(int year = 1,int month = 1,int day = 1){_year = year;_month = month;_day = day;}//计算当前年月所对应的天数int GetMonth(int& year,int& month){int arr[13] ={0,31,28,31,30,31,30,31,31,30,31,30,31};if(month == 2 && ((year % 4 == 0 && year % 100 != 0) || (year % 400 == 0))){return 29;}return arr[month];}//友元函数声明friend ostream& operator<<(ostream& out,Date& d);friend istream& operator>>(istream& out,Date& d);private:int _year;int _month;int _day;
};//赋值运算符重载
ostream& operator<<(ostream& out,Date& d)
{int sum = d._day;--d._month;while(d._month >0){sum += d.GetMonth(d._year, d._month);--d._month;}out<<sum<<endl;  return out;
}
istream& operator>>(istream& in,Date& d)
{in>>d._year>>d._month>>d._day;return in;   
}int main() 
{Date d1;cin>>d1;cout<<d1<<endl;return 0;
}

题二:日期差值

日期差值_牛客题霸_牛客网 (nowcoder.com)

示例1

输入:

20110412
20110422

输出:

11

思路一:

#include <iostream>
using namespace std;
#include <stdbool.h>class Date
{
public:Date(int year = 1, int month = 1, int day = 1){_year = year;_month = month;_day = day;}int GetMonth(int& year, int& month){int arr[13] = { 0,31,28,31,30,31,30,31,31,30,31,30,31 };if (month == 2 && ((year % 4 == 0 && year % 100 != 0) || (year % 400 == 0))){return 29;}return arr[month];}bool operator!=(Date& d){return !(_year == d._year && _month == d._month && _day == d._day);}bool operator<(Date& d){if (_year < d._year){return true;}else if (_year == d._year && _month < d._month){return true;}else if (_year == d._year && _month == d._month && _day < d._day){return true;}return false;}Date& operator++(){++_day;if (_day > GetMonth(_year, _month)){_day = _day - GetMonth(_year, _month);++_month;if (_month == 13){++_year;_month = 1;}}return *this;}int operator-(Date& d){//int flag = 1;Date max = *this;Date min = d;if (*this < d){max = d;min = *this;//flag = -1;}int n = 0;while (min != max){++min;++n;}return n + 1;}friend ostream& operator<<(ostream& out, Date& d);friend istream& operator>>(istream& out, Date& d);private:int _year;int _month;int _day;
};ostream& operator<<(ostream& out, Date& d)
{out << d._year << d._month << d._day << endl;return out;
}istream& operator>>(istream& in, Date& d)
{scanf("%4d%2d%2d", &d._year, &d._month, &d._day);return in;
}int main()
{Date d1;Date d2;cin >> d1;cin >> d2;cout << d1 - d2;return 0;
}
// 64 位输出请用 printf("%lld")

题三:打印日期

打印日期_牛客题霸_牛客网 (nowcoder.com)

示例1

输入:

2000 3
2000 31
2000 40
2000 60
2000 61
2001 60

输出:

2000-01-03
2000-01-31
2000-02-09
2000-02-29
2000-03-01
2001-03-01

思路一:

#include <iostream>
using namespace std;class Date
{
public:Date(int year = 1, int month = 1, int day = 1){_year = year;_month = month;_day = day;}int GetMonth(int& year, int& month){int arr[13] = { 0,31,28,31,30,31,30,31,31,30,31,30,31 };if (month == 2 && ((year % 4 == 0 && year % 100 != 0) || (year % 400 == 0))){return 29;}return arr[month];}void Calendar(){while (_day > GetMonth(_year, _month)){_day = _day - GetMonth(_year, _month);++_month;if (_month == 13){++_year;_month = 1;}}}friend ostream& operator<<(ostream& out, Date& d);friend istream& operator>>(istream& out, Date& d);private:int _year;int _month;int _day;
};ostream& operator<<(ostream& out, Date& d)
{printf("%04d-%02d-%02d", d._year, d._month, d._day);return out;
}
istream& operator>>(istream& in, Date& d)
{scanf("%4d%d", &d._year, &d._day);return in;
}int main()
{Date d1;cin >> d1;d1.Calendar();cout << d1;return 0;
}
// 64 位输出请用 printf("%lld")

题四:日期累加

日期累加_牛客题霸_牛客网 (nowcoder.com)

示例1

输入:

1
2008 2 3 100

输出:

2008-05-13

思路一:

#include <iostream>
using namespace std;class Date
{
public:Date(int year = 1, int month = 1, int day = 1,int sky = 0){_year = year;_month = month;_day = day;_sky = sky;}int GetMonth(int& year, int& month){int arr[13] = { 0,31,28,31,30,31,30,31,31,30,31,30,31 };if (month == 2 && ((year % 4 == 0 && year % 100 != 0) || (year % 400 == 0))){return 29;}return arr[month];}void Calendar(){_day = _day + _sky;while (_day > GetMonth(_year, _month)){_day = _day - GetMonth(_year, _month);++_month;if (_month == 13){++_year;_month = 1;}}}friend ostream& operator<<(ostream& out, Date& d);friend istream& operator>>(istream& out, Date& d);private:int _year;int _month;int _day;int _sky;
};ostream& operator<<(ostream& out, Date& d)
{printf("%04d-%02d-%02d", d._year, d._month, d._day);return out;
}
istream& operator>>(istream& in, Date& d)
{in>>d._year>>d._month>>d._day>>d._sky;return in;
}int main() 
{int n = 0;cin>>n;while(n--){Date d1;cin>>d1;d1.Calendar();cout<<d1<<endl;;}return 0;
}
// 64 位输出请用 printf("%lld")

 

 本人实力有限可能对一些地方解释和理解的不够清晰,可以自己尝试读代码,或者评论区指出错误,望海涵!

感谢大佬们的一键三连! 感谢大佬们的一键三连! 感谢大佬们的一键三连!

                                              

http://www.yayakq.cn/news/888026/

相关文章:

  • 建设一个有影响力的网站最新经济新闻头条
  • 网站开发服务器知识如何在google上免费推广
  • 评价校园网站建设范例wordpress怎样发布时间
  • 织梦网站普通地图插件诸城做网站的
  • 景安网络网站建设广东深圳华强北
  • 户外家具技术支持东莞网站建设wordpress无法拖动小工具栏
  • 忻州建设公司网站哈尔版网站建设
  • 济南网站建设 力推聚搜网络网页小游戏入口
  • 网站正能量就是一打开全是的盱眙网站建设公司
  • 电商网站策划温州市网络公司网站建设公司
  • 地方生活门户网站建设方案广州网站优化关键词公司
  • 17做网店网站丽水做企业网站的公司
  • 淄博网站建设铭盛信息网站如何防止别人抄袭
  • 网页页面下载佛山网站优化平台
  • 温州网络优化公司抖音优化公司
  • 网站规划与网页设计腾讯qq
  • 保定网站建设方案咨询微营销
  • 网站建设公司的企业特色有哪些百度下载电脑版
  • 常州网站搭建公司wordpress动漫主题
  • 电子商务网站功能一级消防工程师考试试题及答案
  • 做电商卖玉器的网站网站推广的营销策划方案
  • 网站收录查询网做质粒图谱的网站
  • 公司网站平台的作用工业产品外观设计公司
  • 营销型网站三要素中国男女直接做的视频网站
  • 佛山网站建设流程国家工程建设信息网站
  • 免费网站推广工具有哪些除了做视频网站还能做什么网站
  • 大连微信网站建设搜索引擎下载
  • 智能建站公司大学生html网页设计期末作品
  • 大型企业网站建设腾虎广州网站建设
  • 网站建设图片尺寸微信推广赚钱