CQUPT计算机复试2015a卷代码题

CQUPT 复试 代码题15a

搬运请注明出处!!!

#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <string.h>
#include <malloc.h>
#include <math.h>
#include <stdlib.h>
#include <stack>
#include <queue>
#include <random>
using namespace std;
#define N 100
// 15a-1 adddigit------------------------------------------
// int adddigit(int num)
// {
//     int k, sum = 0;
//     while (num)
//     {
//         k = num % 10;
//         sum += k;
//         num /= 10;
//     }
//     return sum;
// }
// int main(int argc, char const *argv[])
// {
//     int num;
//     scanf("%d", &num);
//     printf("%d", adddigit(num));
//     return 0;
// }
// 15a-2 chrn-----------------------------------------------
// int chrn(char *s, char c)
// {
//     int count = 0;
//     while (*s)
//     {
//         if (*s == c)
//         {
//             count++;
//         }
//         s++;
//     }
//     return count;
// }
// int main(int argc, char const *argv[])
// {
//     char s[N], c;
//     gets(s);
//     scanf("%c", &c);
//     printf("count=%d", chrn(s, c));
//     return 0;
// }
// 15a-3 打鱼or晒网-----------------------------------------------
// 判断闰年
int isLeapyear(int year)
{
    int f = 0;
    if ((year % 4 == 0 && year % 100 != 0) || (year % 400 == 0))
    {
        f = 1;
    }
    return f;
}
// 返回月份的天数
int GetMonthdays(unsigned int year, unsigned int month)
{
    int days = 0;
    if (month == 1 || month == 3 || month == 5 || month == 7 || month == 8 || month == 10 || month == 12)
    {
        days = 31;
    }
    else if (month == 4 || month == 6 || month == 9 || month == 11)
    {
        days = 30;
    }
    else if (month == 2)
    {
        if (isLeapyear(year))
            days = 29;
        else
            days = 28;
    }
    return days;
}
int isWorking(unsigned int year, unsigned int month, unsigned int day)
{
    int count = 1;
    int start_y = 1990, start_m = 1, start_d = 1;                 // 初始日期
    while (start_y != year || start_m != month || start_d != day) // 改变初始日期,一直到输入日期为止
    {
        // cout << start_y << start_m << start_d << endl;
        if (start_d != GetMonthdays(start_y, start_m))
        {
            start_d += 1;
        }
        else
        {
            if (start_m != 12) // 不是12月31号,但是是1-11月的最后一天
            {
                start_m += 1;
                start_d = 1;
            }
            else // 是12月31号
            {
                start_y += 1;
                start_m = start_d = 1;
            }
        }
        count += 1; // 记录距离多少天
    }
    return count;
}
int main(int argc, char const *argv[])
{
    unsigned int y, m, d;
    scanf("%d,%d,%d", &y, &m, &d);
    // cout << isWorking(y, m, d) << endl;
    if (isWorking(y, m, d) % 5 != 4 && isWorking(y, m, d) % 5 != 0)
    {
        printf("打鱼\n");
    }
    else
    {
        printf("晒网\n");
    }
    return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值