中国有句俗语叫“三天打鱼两天晒网”,某人从90年1月1日起开始“三天打鱼两天晒网”。问这个人在以后的某一天中是在“打渔”,还是在“晒网”(数组,循环,函数)
中国有句俗语叫“三天打鱼两天晒网”,某人从90年1月1日起开始“三天打鱼两天晒网”。问这个人在以后的某一天中是在“打渔”,还是在“晒网”.
更改之后的,正确的完整的,有判断不合法时间的的代码
#include <stdio.h>
int panDuanRunNian ( int year);
int main(int argc, const char * argv[])
{//printf("Enter year/month/day:");int year, b, c;scanf("%d-%d-%d",&year,&b,&c);if (year<1||b>12||b<1||c>31||c<1) {printf("Input error!\n");return 0;}//错误类型一:闰年二月if ((year%4==0&&year%100!=0)||(year%400==0)) {if (b == 2&& c > 29) {printf("Input error!\n");return 0;}}else{if (b==2&& c > 28) {printf("Input error!\n");return 0;}}//其他月份的日期没对上if(b == 1||b == 3||b==5||b==7||b==8||b==10||b==12){if (c>31) {printf("Input error!\n");return 0;}}else{if (c>30) {printf("Input error!\n");return 0;}}int d = 0;int a = panDuanRunNian(year);int arr[2][12]={{31,29,31,30,31,30,31,31,30,31,30,31},{31,28,31,30,31,30,31,31,30,31,30,31}};for (int i = 1900; i < year - 1900; i++) {if (panDuanRunNian(i)==1) d+=366;else d+=365;}for (int i = 1; i < b; i++) {if (a == 1) d+=arr[0][i-1];else d+=arr[1][i-1];}if ((d+c)%5 == 0||(d+c)%5 == 4) printf("He is sleeping.\n");elseprintf("He is working\n");return 0;
}
int panDuanRunNian ( int year)
{return (year%400==0||(year%4==0&&year%100!=0));
}
运行结果
2020-01-01
He is working
Program ended with exit code: 0
标准答案
参考答案
#include <stdio.h>
#include <stdlib.h>int main()
{ int y, m, d;int sum = 0;scanf("%4d-%2d-%2d", &y, &m, &d);if (y < 1990){ printf("Invalid input.");return 0;}if ((y % 100 != 0 && y % 4 == 0) || (y % 400 == 0)){ switch (m){ case 1:case 3:case 5:case 7:case 8:case 10:case 12:if (d > 31 || d < 1){ printf("Invalid input.");return 0;}break;case 2:if (d > 29 || d < 1){ printf("Invalid input.");return 0;}break;case 4:case 6:case 9:case 11:if (d > 30 || d < 1){ printf("Invalid input.");return 0;}break;default:printf("Invalid input.");return 0;break;}}else{ switch (m){ case 1:case 3:case 5:case 7:case 8:case 10:case 12:if (d > 31 || d < 1){ printf("Invalid input.");return 0;}break;case 2:if (d > 28 || d < 1){ printf("Invalid input.");return 0;}break;case 4:case 6:case 9:case 11:if (d > 30 || d < 1){ printf("Invalid input.");return 0;}break;default:printf("Invalid input.");return 0;break;}}int i;if (y > 1990){ for (i = 1990; i < y; i++){ if ((i % 100 != 0 && i % 4 == 0) || (i % 400 == 0)){ sum = sum + 366;}else{ sum = sum + 365;}}}int i1;if (m > 1){ for (i1 = 1; i1 < m; i1++){ if ((y % 100 != 0 && y % 4 == 0) || (y % 400 == 0)){ switch (i1){ case 1:case 3:case 5:case 7:case 8:case 10:case 12:sum = sum + 31;break;case 2:sum = sum + 29;break;case 4:case 6:case 9:case 11:sum = sum + 30;break;}}else{ switch (i1){ case 1:case 3:case 5:case 7:case 8:case 10:case 12:sum = sum + 31;break;case 2:sum = sum + 28;break;case 4:case 6:case 9:case 11:sum = sum + 30;break;}}}}sum = sum + d;sum = sum % 5;if (sum == 0 || sum == 4){ printf("He is having a rest.");}else{ printf("He is working.");}return 0;
}
下面是之前的解法,忘记什么时候了/之前的应该有问题没有改的/
#include <stdio.h>
int main()
{int y,m,d;//年月日年月日年月日scanf("%4d-%2d-%2d",&y,&m,&d);int arr[2][12] = {{31,29,31,30,31,30,31,31,30,31,30,31},{31,28,31,30,31,30,31,31,30,31,30,31}};//不满足条件的日期先去掉if(y < 1990||m>12||d>31){printf("Invalid input");return 0;}int days = 0;//yearfor(int i = 1990; i< y;i++){if((i%400 == 0) || ((i%4 == 0 )&&(i%100 != 0)) )//闰年366{days += 366;}else{days += 365;}}//monthif(y%400 == 0 || ((y%4 == 0 )&&(y%100 == 0)) )for(int i = 0;i < m-1;i++) days+=arr[0][i];elsefor(int i = 0;i < m-1;i++) days+=arr[1][i];//daydays += d;if(days % 5 <= 3 && days % 5 != 0 )printf("He is working");elseprintf("He is having a rest");return 0;
}
中国有句俗语叫“三天打鱼两天晒网”,某人从90年1月1日起开始“三天打鱼两天晒网”。问这个人在以后的某一天中是在“打渔”,还是在“晒网”(数组,循环,函数)相关推荐
- 中国有句俗语叫“三天打鱼两天晒网”,某人从90年1月1日起开始“三天打鱼两天晒网”。问这个人在以后的某一天中是在“打渔”,还是在“晒网”. **输入格式要求:“%d%d%d“ 提示信息:“Enter
中国有句俗语叫"三天打鱼两天晒网",某人从90年1月1日起开始"三天打鱼两天晒网".问这个人在以后的某一天中是在"打渔",还是在" ...
- 中国有句俗语叫“三天打鱼两天晒网”,某人从90年1月1日起开始“三天打鱼两天晒网”。问这个人在以后的某一天中是在“打渔”,还是在“睡觉”.**输入格式要求:“%d%d%d“ 提示信息:
运用结构体 for (k = 1990; k < DATE.year; k++) { if ((k % 4 == 0 && k % 100 != 0) || k ...
- 中国有句俗语叫“三天打鱼两天晒网”。某人从2010年1月1日起开始“三天打鱼两天晒网”,问这个人在以后的某一天中是“打鱼”还是“晒网”。
问题描述:中国有句俗语叫"三天打鱼两天晒网".某人从2010年1月1日起开始"三天打鱼两天晒网",问这个人在以后的某一天中是"打鱼"还是&q ...
- 中国有句俗语叫“三天打鱼两天晒网”。某人从2010年1月1日起开始“三天打鱼两天晒网”,问这个人在以后的某一天中是“打鱼”还是“晒网”。用java实现程序解决问题。
一丶中国有句俗语叫"三天打鱼两天晒网".某人从2010年1月1日起开始"三天打鱼两天晒网",问这个人在以后的某一天中是"打鱼"还是" ...
- 中国有句俗语叫“三天打鱼两天晒网”。某人从2010年1月1日起开始“三天打鱼两天晒网”,问这个人在以后的某一天中是“打鱼”还是“晒网”
问题: 中国有句俗语叫"三天打鱼两天晒网".某人从2010年1月1日起开始"三天打鱼两天晒网",问这个人在以后的某一天中是"打鱼"还是&qu ...
- 中国有句俗语叫“三天打鱼两天晒网”。某人从2010年1月1日起开始“三天打鱼两天晒网”, 问这个人在以后的某一天中是“打鱼”还是“晒网”。用C或C++语言/java/python实现程序解决问题
/* 中国有句俗语叫"三天打鱼两天晒网".某人从2010年1月1日起开始"三天打鱼两天晒网", 问这个人在以后的某一天中是"打鱼"还是&qu ...
- 中国有句俗语叫“三天打鱼两天晒网”。 某人从2010年1月1日起开始“三天打鱼两天晒网”, 问这个人在以后的某一天中是“打鱼”还是“晒网”
此题目难度不大,主要难度在于所给日期闰年判定以及经过的年份中闰年的个数问题, 对于输入日期的中日正确性判断,只需建立对应月份天数的数组即可判断.求出所给年份到初始年份经过的天数后对五取余判定是否大于三 ...
- 7-16 三天打鱼两天晒网 (15分) 中国有句俗语叫“三天打鱼两天晒网”。假设某人从某天起,开始“三天打鱼两天晒网”,问这个人在以后的第N天中是“打鱼”还是“晒网”?
7-16 三天打鱼两天晒网 (15分) 中国有句俗语叫"三天打鱼两天晒网".假设某人从某天起,开始"三天打鱼两天晒网",问这个人在以后的第N天中是"打 ...
- 中国有句俗语叫“三天打鱼两天晒网”。假设某人从说明某天起,开始“三天打鱼两天晒网”,问这个人在以后的第N天中是“打鱼”还是“晒网”?
中国有句俗语叫"三天打鱼两天晒网".假设某人从说明某天起,开始"三天打鱼两天晒网",问这个人在以后的第N天中是"打鱼"还是"晒网& ...
最新文章
- golang time.After 超时使用理解
- mysql load xml_MySQL的SQL语句 - 数据操作语句(10)- LOAD XML 语句
- Linux使用locate命令查找,Linux如何使用locate命令查找数据(2)
- Android程序设计基础-设计布局之伪今日头条主界面
- 如何实现Oracle数据库之间的数据同步?
- linux ntp软件下载,Linux_Linux时区同步问题(安装ntp软件过程),下载了一个windows的NTP服务程序 - phpStudy...
- angular-数据绑定的最佳实践
- [hdu1242]优先队列
- KinectFusion: Real-Time Dense Surface Mapping and Tracking
- 填表法解“银行家算法”问题
- HDU 5586 Sum
- 黄健计算机科学与技术学院,计算机科学与技术学院研究生学业奖学金初评结果汇总表...
- ARM64体系结构编程与实践:基础知识
- Python打包exe,以及解决闪退
- pci总线扫描及pci网卡驱动
- 解决:outlook邮件内容过宽,打印不全
- Mac上实时网速、内存等显示
- 计算机术语输入的英文缩写,计算机术语英文缩写
- 微信H5如何关闭浏览器(如何监听手机的物理返回键)
- 深入理解机器学习——类别不平衡学习(Imbalanced Learning):性能评价测度