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

网站建设合同谷歌收录提交入口

网站建设合同,谷歌收录提交入口,建设网站好处,网站建设与管理维护 李建青文章目录 1. 求123...n2. 计算是这一年的第几天3. 求两个日期之间的天数4. 算出第n天是几月几号5. 计算一个日期加上若干天后是什么日期 1. 求123…n 求123…n,要求不能使用乘除法、for、while、if、else、switch、case等关键字及条件判断语句(A?B:C&a…

文章目录

      • 1. 求1+2+3+...+n
      • 2. 计算是这一年的第几天
      • 3. 求两个日期之间的天数
      • 4. 算出第n天是几月几号
      • 5. 计算一个日期加上若干天后是什么日期


1. 求1+2+3+…+n

求1+2+3+…+n,要求不能使用乘除法、for、while、if、else、switch、case等关键字及条件判断语句(A?B:C)。

数据范围: 0 < n <= 200

class func{
public:static int i;static int sum;func(){sum+=i;++i;}
};int func::i = 1;
int func::sum = 0;class Solution {
public:int Sum_Solution(int n) {func* p = new func[n];return func::sum;}
};

2. 计算是这一年的第几天

根据输入的日期,计算是这一年的第几天。

保证年份为4位数且日期合法。

#include <iostream>
using namespace std;class Date{
public:int year;int month;int day;Date(){};// 声明友元friend istream& operator>>(istream& in, Date& d);// 判断闰年bool isLeapYear(int year) const{return((year % 4 == 0 && year % 100 != 0) || year % 400 == 0);}// 获得日期int Getday(int year, int month) const{static const int Getdays[] =  {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};if(month == 2 && isLeapYear(year))return 29;return Getdays[month - 1];}// 计算是这一年的第几天int my_sum(int year, int month, int day) const{int sum = 0;for(int i = 1;i < month; ++i){sum += Getday(year, i); }sum += day;return sum;}
};// >> 操作符重载
istream& operator>>(istream& in, Date& d){in >> d.year >> d.month >> d.day;return in;
}int main()
{Date d;while(cin >> d){cout << d.my_sum(d.year, d.month, d.day) << endl;}return 0;
}

3. 求两个日期之间的天数

有两个日期,求两个日期之间的天数,如果两个日期是连续的我们规定他们之间的天数为两天

#include <bits/stdc++.h>
using namespace std;
int day[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};
int leap(int year){if((year%4==0 && year%100!=0) || year%400==0) return 1;return 0;
}int main(){int day1,day2,mon1,mon2,year1,year2;scanf("%4d%2d%2d",&year1,&mon1,&day1);scanf("%4d%2d%2d",&year2,&mon2,&day2);int sum1=0,sum2=0;for(int yy=0;yy<year1;yy++){if(leap(yy)) sum1+=366;else sum1+=365;} if(leap(year1)) day[2]=29;else day[2]=28;for(int mm=1;mm<mon1;mm++){sum1+=day[mm];}sum1+=day1;for(int yy=0;yy<year2;yy++){if(leap(yy)) sum2+=366;else sum2+=365;} if(leap(year2)) day[2]=29;else day[2]=28;for(int mm=1;mm<mon2;mm++){sum2+=day[mm];}sum2+=day2;cout<<abs(sum1-sum2)+1<<endl;return 0;
}

4. 算出第n天是几月几号

给出年分m和一年中的第n天,算出第n天是几月几号。

#include <iostream>
using namespace std;class Date {public:// 判断是否为闰年bool isLeapYear(int year) const {if ((year % 4 == 0 && year % 100 != 0) || year % 400 == 0)return true;return false;}// 获取某年某月的天数int GetMonthDay(int year, int month) const {static const int GetMonthDay[] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };if (month == 2 && isLeapYear(year))return 29;return GetMonthDay[month - 1];}// 构造函数Date(int year, int x) {this->year = year;if (x <= 31) {month = 1;day = x;} else {x -= 31;month = 2;for (int i = 2; x > GetMonthDay(year, i); ++i) {++month;x -= GetMonthDay(year, i);}day = x;}  }private:int year;int month;int day;friend ostream& operator<<(ostream& out, const Date& d);
};// << 运算符重载
ostream& operator<<(ostream& out, const Date& d) {if (d.month < 10 &&d.day < 10)   out << d.year << "-0" << d.month << "-0" << d.day << endl;else if (d.month < 10)   out << d.year << "-0" << d.month << "-" << d.day <<endl;else if (d.day < 10)   out << d.year << "-" << d.month << "-0" << d.day << endl;else   out << d.year << "-" << d.month << "-" << d.day << endl;return out;
}int main() {int year, x;while (cin >> year >> x){Date d(year, x);cout << d;}return 0;
}

5. 计算一个日期加上若干天后是什么日期

设计一个程序能计算一个日期加上若干天后是什么日期。

#include <iostream>
using namespace std;class Date {
public:// 判断是否为闰年bool isLeapYear(int year) const {if ((year % 4 == 0 && year % 100 != 0) || year % 400 == 0)return true;return false;}// 获取某年某月的天数int GetMonthDay(int year, int month) const {static const int GetMonthDay[] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };if (month == 2 && isLeapYear(year))return 29;return GetMonthDay[month - 1];}// 日期天数递增一天void incrementDate() {++day;if (day > GetMonthDay(year, month)) {day = 1;++month;if (month > 12) {month = 1;++year;}}}// 后置++运算符重载Date& operator++(){Date tmp = *this;incrementDate();return *this;}Date(int year, int month, int day): year(year), month(month), day(day) {}private:int year;int month;int day;friend ostream& operator<<(ostream& out, const Date& d);
};// << 运算符重载
ostream& operator<<(ostream& out, const Date& d) {if (d.month < 10 && d.day < 10)   out << d.year << "-0" << d.month << "-0" << d.day << endl;else if (d.month < 10)   out << d.year << "-0" << d.month << "-" << d.day <<endl;else if (d.day < 10)   out << d.year << "-" << d.month << "-0" << d.day << endl;else   out << d.year << "-" << d.month << "-" << d.day << endl;return out;
}int main() {int n;int y, m, d, x;cin >> n;for (int i = 0; i < n; ++i) {cin >> y >> m >> d >> x;Date d1(y, m, d);while(x--){++d1;}cout << d1;}return 0;
}
http://www.yidumall.com/news/41492.html

相关文章:

  • 上海网站建设 知名做百度搜索排名靠前
  • 建设网站的目标和作用做推广网络
  • 来年做哪个网站致富百度联系方式人工客服
  • 虎门今天新增疫情搜索引擎优化效果
  • 美食网站开发现状seo优化网络公司
  • 网站联动是什么意思海洋网络推广效果
  • 网站变exe文件怎么做营销网站优化推广
  • web网站如何用div做日历客户管理软件
  • 做站长建不好网站最好的营销策划公司
  • wordpress博客xiuseo高效优化
  • WordPress百度智能小程序seo站外优化平台
  • 苹果id钓鱼网站怎么做线上电脑培训班
  • 昆山网站建设公司发表文章的平台有哪些
  • 天长街道两学一做网站建设网站费用
  • 网页提示站点不安全网络市场调研的五个步骤
  • 一个人做的网站做什么好搜索引擎优化包括
  • 动态网站建设论文公司如何建立网站
  • 门户网站维护方案广州网络推广定制
  • 化妆品网站开发步骤卫星电视安装视频
  • 短视频seo公司北京seo优化哪家好
  • 网站怎么做房源安徽百度seo公司
  • 一个网站要注意哪些问题专业网络推广机构
  • 国内做的好网站有哪些北京seo优化排名
  • 唐山网站建设优化seo专业培训课程
  • 做网站前端用什么北京seo优化哪家好
  • 大连装修公司哪家靠谱热门seo推广排名稳定
  • 代做效果图的网站微信推广平台
  • 手机兼职赚钱一单一结微信群郑州网站优化外包
  • 建筑网站的功能模块软文推广去哪个平台好
  • 网站建设合同注意点国外搜索引擎大全