第16周阅读程序4(2)

/* 
 * Copyright(c)2016,烟台大学计算机与控制工程学院 
 * All rights reserved. 
 * 文件名称:第16周阅读程序4(2)
 * 作者:马康泰
 * 完成日期:2016.6.15 
 * 版本号:v1.0 
 * 
 * 问题描述:阅读下面的程序,指出其功能,体会seekg()、tellg()等函数的功能及其用法 
 * 输入描述: 
 * 程序输出: 
 */  
#include <fstream>
using namespace std;
int main ()
{
    long pos;
    ofstream outfile;
    outfile.open ("test.txt");
    outfile.write ("This is an apple",16);
    pos=outfile.tellp();
    outfile.seekp (pos-7);
    outfile.write (" sam",4);
    outfile.close();
    return 0;
}
}

如果我们要设计一个简单的程序来模拟每工作四天、不休息的情况,我们首先需要明确的是每""的具体定义。假设这里的一是指五个完整的工作日,那么在一年365天里,我们可以按这样的规则计算: 1. 每月通常有四个完整的星期,即28天(平月)或29天(闰月),其中最多可以工作16天(4*4天)。 2. 如果有剩余的天数,比如一个月的第一天是一个工作日,那么这个月最后一天也是工作日,这样也算作工作日。 下面是一个简单的Python程序示例,用于计算这种工作模式下的总工作天数: ```python def weekly_work_days(year): work_days_per_week = 4 days_in_year = year * 365 leap_years = sum(1 for i in range(1, year + 1) if (i % 4 == 0 and i % 100 != 0) or (i % 400 == 0)) # 计算闰年的个数 regular_months = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31] # 非闰年每月天数 leap_months = [31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31] # 闰年每月天数 total_work_days = 0 for month_days in regular_months + leap_months: if month_days <= 4: total_work_days += month_days * work_days_per_week else: weeks_in_month = month_days // work_days_per_week remaining_days = month_days % work_days_per_week total_work_days += weeks_in_month * work_days_per_week + remaining_days return total_work_days year = 2023 # 输入你想查询的年份 work_days = weekly_work_days(year) print(f"在{year}年,按照每工作4天、不休息的制度,总共有 {work_days} 天工作.") #
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值