OJ 嘻刷刷 我想放假
来源:互联网 发布:centos终端能输入中文 编辑:程序博客网 时间:2024/04/30 11:56
Problem D: 我想放假
Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 102 Solved: 37
[Submit][Status][Web Board]
Description
小明的弟弟上小学了,每次刚入学就想知道什么时候放假,但是每学期开学的日子和每学期的有效天数都不一样,请你编程帮他计算放假日期。
本题只需要提交填空部分
#include <iostream>
using namespace std;
class Date
{
public:
void input(int y,int m,int d);
friend Date operator+(Date &c,int &day);
void display();
private:
int year;
int month;
int day;
};
void Date::input(int y,int m,int d)
{
year=y;
month=m;
day=d;
}
Date operator+(Date &c,int &day)
{
/*********************/
填空部分
/*********************/
}
void Date::display()
{
cout<<year<<"/"<<month<<"/"<<day<<endl;
}
int main()
{
Date date1,date2;
int y,m,d;
int day;
cin>>y>>m>>d;
date1.input(y,m,d);
cin>>day;
date2=date1+day;
date2.display();
return 0;
}
Input
第一行输入开学的年月日,以空格隔开;第二行输入本学期的有效天数
Output
输出计算后得到的放假日期,格式为年/月/日。
Sample Input
2008 2 29140
Sample Output
2008/7/18
代码:
#include <iostream>using namespace std;class Date{public: void input(int y,int m,int d); friend Date operator+(Date &c,int &day); void display();private: int year; int month; int day;};void Date::input(int y,int m,int d){ year=y; month=m; day=d;}Date operator+(Date &c,int &day){ int a[13]={0,31,28,31,30,31,30,31,31,30,31,30,31}; if((c.year%4==0&&c.year%100!=0)||(c.year%400==0)) a[2]=29; c.day+=day; while (c.day>a[c.month]) { c.day-=a[c.month]; c.month++; if(c.month>12) { c.year++; c.month-=12; } a[2]=((c.year%4==0&&c.year%100!=0)||(c.year%400==0))?29:28; } return c;}void Date::display(){ cout<<year<<"/"<<month<<"/"<<day<<endl;}int main(){ Date date1,date2; int y,m,d; int day; cin>>y>>m>>d; date1.input(y,m,d); cin>>day; date2=date1+day; date2.display(); return 0;}
运行结果:
0 0
- OJ 嘻刷刷 我想放假
- OJ嘻唰唰 我想放假
- OJ刷题我想放假
- YTU 2911: 我想放假
- [YTU]_2911 ( 我想放假)
- [YTU]_2911(我想放假)
- 34嘻刷刷
- 6.15 喜刷刷1 oj 数组输出
- 6.15 喜刷刷 oj 1 b 矩形类定义
- 6.15 喜刷刷 1 oj 1 对象数组中的最大值
- 放假
- 放假
- 放假
- 放假!
- 放假
- 放假
- 放假
- 放假
- 运用JS设置cookie、读取cookie、删除cookie
- iOS 读取图片的各种方法
- Android Studio使用OpenCV的配置方法
- xml和json相互转换的代码
- stm32Flash模拟eeprom心得(原创)
- OJ 嘻刷刷 我想放假
- Qt Project Build error PRJ0019: 工具从"Moc'ing xxx.h..."
- NSDictionary或NSArray与JSON字符串相互转换
- iptables 只拒绝某个ip的所有连接
- settimeout计时器实例
- Guess3
- habernate注解模式多表关联
- 贴片电容器容量怎么换算?
- Linux中查看CPU信息