鱼C论坛

 找回密码
 立即注册
查看: 3398|回复: 0

[学习笔记] “三天打鱼两天晒网”,某人从1990年1月1日起开始“三天打鱼两天晒网”。问这个人...

[复制链接]
发表于 2021-5-18 18:14:11 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
  1. #include<stdio.h>
  2. long y_tianshu(int y);
  3. int n_tianshu(int y, int n);
  4. int T(int y, int n,int d);

  5. long y_tianshu(int y)//计算当年之前的天数
  6. {

  7. long a=0;

  8. if (y == 1990) a = 0;

  9. else if (y == 1991) a = 365;

  10. else if (y == 1992) a = 365 * 2;

  11. else if (y == 1993) a = 365 * 2 + 366;

  12. else if (y > 1993 && y < 1997)

  13. a = 365 * 2 + 366 + (y - 1993) * 365;

  14. else if (y >= 1997)

  15. a = 365 * 2 + 366 + (y - 1993) * 365 + (y - 1993) / 4;

  16. return a;
  17. }

  18. int n_tianshu(int y, int n)//计算在本年,当月之前的天数
  19. {
  20. int s; int b=0;
  21. for (int a = 1; a <= n - 1; a++)
  22. {

  23.     switch (a)//根据月份判断天数
  24.     {

  25.     case 1:s = 31; break; case 2:s = 28; break;

  26.     case 3:s = 31; break; case 4:s = 30; break;
  27.    
  28.     case 5:s = 31; break; case 6:s = 30; break;

  29.     case 7:s = 31; break; case 8:s = 31; break;

  30.     case 9:s = 30; break; case 10:s = 31; break;

  31.     case 11:s = 30; break; case 12:s = 31; break;
  32.     }

  33.     if (a == 2)//判断闰年2月差异
  34.     {
  35.         if (y % 4 == 0 && y % 100 != 0 || y % 400 == 0)
  36.         s = 29;

  37.         else
  38.         s = 28;
  39.     }

  40.     b = b + s;
  41. }
  42. return b;
  43. }

  44. int T(int y, int n,int d)//判断输入的月份的天数是否正确
  45. {
  46. int s=0;

  47. switch (n)//根据月份判断天数
  48. {
  49. case 1:s = 31; break; case 2:s = 28; break;

  50. case 3:s = 31; break; case 4:s = 30; break;

  51. case 5:s = 31; break; case 6:s = 30; break;

  52. case 7:s = 31; break; case 8:s = 31; break;

  53. case 9:s = 30; break; case 10:s = 31; break;

  54. case 11:s = 30; break; case 12:s = 31; break;
  55. }

  56. if (n == 2)//判断闰年2月差异
  57. {
  58.     if (y % 4 == 0 && y % 100 != 0 || y % 400 == 0)
  59.     s = 29;

  60.     else
  61.     s = 28;
  62. }

  63. if (d <= s) return 0;
  64. else return 1;
  65. }

  66. void main()
  67. {

  68. int y, n, d;

  69. while (1)
  70. {
  71.     scanf_s("%d-%d-%d", &y, &n, &d);//输入时间
  72.    
  73.     while (y <= 0 || n <= 0 || d <= 0 || y < 1990||T(y, n, d)||n>12)

  74.     {    //控制输入的数据为正,并且在1990之后
  75.         //控制相应月份对应所具有的相应天数

  76.         printf("input error!please re-input:\n");
  77.    
  78.         scanf_s("%d-%d-%d", &y, &n, &d);

  79.     }

  80.     long a = y_tianshu(y) + n_tianshu(y, n) + d;
  81.     a = a % 5;

  82.     if (a <= 3&&a>0) printf("他在打鱼\n");//利用总日子除以5的余数判断
  83.     else printf("他在晒网\n");
  84. }
  85. }
复制代码
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2025-4-25 16:04

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表