Friday the Thirteenth

Friday the Thirteenth 黑色星期五 ** Friday the Thirteenth 黑色星期五 ** 解题思路来自NOCOW 题目: 13 号又是星期五是一个不寻常的日子吗? 13 号在星期五比在其他日少吗?为了回答这个问题,写一个程序来计算在 n 年里 13 日落在星期一,星期二…星期日的次数.这个测试从 1900 年 1 月 1 日到 1900+n-1 年 12 月 31 日.n 是一个非负数且不大于 400. 这里有一些你要知道的: 1900 年 1 月 1 日是星期一. 4,6,11 和 9 月有 30 天.其他月份除了 2 月有 阅读详情

Friday the Thirteenth

Is Friday the 13th really an unusual event?

That is, does the 13th of the month land on a Friday less often than on any other day of the week? To answer this question, write a program that will compute the frequency that the 13th of each month lands on Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, and Saturday over a given period of N years. The time period to test will be from January 1, 1900 to December 31, 1900+N-1 for a given number of years, N. N is positive and will not exceed 400.

Note that the start year is NINETEEN HUNDRED, not NINETEEN NINETY.

There are few facts you need to know before you can solve this problem:

• January 1, 1900 was on a Monday.
• Thirty days has September, April, June, and November, all the rest have 31 except for February which has 28 except in leap years when it has 29.
• Every year evenly divisible by 4 is a leap year (1992 = 4*498 so 1992 will be a leap year, but the year 1990 is not a leap year)
• The rule above does not hold for century years. Century years divisible by 400 are leap years, all other are not. Thus, the century years 1700, 1800, 1900 and 2100 are not leap years, but 2000 is a leap year.
Do not use any built-in date functions in your computer language.

Don’t just precompute the answers, either, please.

INPUT FORMAT

One line with the integer N.

SAMPLE INPUT

20

OUTPUT FORMAT

Seven space separated integers on one line. These integers represent the number of times the 13th falls on Saturday, Sunday, Monday, Tuesday, …, Friday.

SAMPLE OUTPUT

36 33 34 33 35 35 34

C++编写:

这道题还是先理一下思路比较好,想好怎么做就可以动手了,注意一下输出格式就好,代码如下:

/*
ID: your_id_here
TASK: friday
LANG: C++                 
*/
#include<iostream>
#include<cstdio>
using namespace std;

int N;
int month_days[12]={31,28,31,30,31,30,31,31,30,31,30,31};
int week[7]={0};                 /*顺序为Saturday, Sunday, Monday, Tuesday, Wednesday, Thursday, Friday. */
int index=0;     /*因为1900年1月13日为星期六 */

bool isLeapYear(int year)
{
    return year % 400 == 0 || (year % 4 == 0 && year % 100 != 0); 
}

void solve()
{
    for(int i=1900;i<1900+N;i++)
    {
        month_days[1]=isLeapYear(i)?29:28;  
        for(int j=0;j<12;j++)
        {
            week[index]++;
            index+=month_days[j];            /*两个月同一个日子相隔的天数为上一个月的总天数 */
            index%=7;
        }
    }
    for(int k=0;k<6;k++)
        cout<<week[k]<<" ";
    cout<<week[6]<<endl;
}

int main()
{
    freopen("friday.in","r",stdin);
    freopen("friday.out","w",stdout);

    cin>>N;
    solve();
}
Mobile Partner.exe.rar Mobile Partner 华为 移动 伴侣 华为电信3G(EVDO)ExpressCard口(E口)网卡打电话、发短信软件 说明: 1、此软件连接网络会产生流量,但电话功能不需要连接网络。使用此本软件可以在上网时接打电话、收发短信,并有通话记录和短信箱。 2、使用软件之前,该网卡应能正常连接无线网络和收发数据。 3、使用此软件之前,请先断开网络、退出默认的网络连接程序。然后启动解压后目录中的程序“Mobile Partner.exe”。 绝对支持的型号: 华为EC8189 华为EC1260 华为EC122 其他型号是否支持请可参考 http://xloli.net/html/201010/thread-1861-1-1.html#axzz1C2lkguqt 立即下载

相关推荐

华为打电话的拨号程序(Mobile Partner 全功能修改版)

华为打电话的拨号程序(Mobile Partner 全功能修改版

Friday the Thirteenth(模拟)

Friday the Thirteenth Is Friday the 13th really an unusual event? That is, does the 13th of the month land on a Friday less often than on any other day of the week? To answer this question, write a...

Simone chou... 220

html5选择城市天气预报代码

使用html5和jq来写的天气预报,默认调用了第三方的api接口,可以实时的看到天气预报情况,各位老铁看着情况需要来下载

2017年华为官方提供的免费学习资源

无线网络:{HCNA(课程:http://support.huawei.com/learning/nodeQueryAction!loadTrainProjectInfo?lang=zh&amp;pbiPath=term1000025181&amp;courseId=Node1000011676&amp;navId=MW000001教材:http://s...

我的学习笔记 1166

华为云Stack的学习(三)

LVS是四层负载均衡,建立在OSI模型的传输层之上,所以效率非常高。NAT模式的转发主要通过修改IP地址(位于OSI模型的第三层网络层)实现转发。DR模式的转发主要通过修改MAC地址(位于OSI模型的第二层数据链路层)实现转发。云服务框架中使用的DR模式。域名解析服务器分为管理侧(OM)和租户侧(Tenant)**DNS-OM:**作为云服务的本地DNS服务器,为云服务提供域名解析服务,并代理公网域名的解析。

Ciyaso的博客 8561

工业界实战:小红书推荐系统中的AB测试策略解析——分层、Holdout与反转实验

本文深入解析了小红书推荐系统在工业界实践中采用的AB测试核心策略。重点阐述了分层实验如何解决多实验并行与干扰问题,Holdout机制如何作为评估黄金标准提供稳定基准,以及反转实验如何作为全量上线后的终极安全网进行风险控制。这些策略共同构成了科学、严谨的线上评估体系,是保障推荐系统迭代效果与决策质量的关键。

transformer2023的博客 475

USACO Friday the Thirteenth

Friday the Thirteenth Is Friday the 13th really an unusual event? That is, does the 13th of the month land on a Friday less often than on any other day of the week? To answer this question, wr

笨小孩的专栏 591

Reeds-Shepp曲线公式推导及代码实现-第二部分(共三部分)

文章目录2. Reeds-Shepp求解2.1 L+S+L+L^+S^+L^+L+S+L+2.2 L+S+R+L^+S^+R^+L+S+R+2.3 L+R−L+L^+R^-L^+L+R−L+2.4 L+R−L−L^+R^-L^-L+R−L−2.5 L+R+L−L^+R^+L^-L+R+L−2.6 L+Rβ+Lβ−R−L^+R_{\beta}^+L_{\beta}^-R^-L+Rβ+​Lβ−​R−2.7 L+Rβ−Lβ−R+L^+R_{\beta}^-L_{\beta}^-R^+L+Rβ−​Lβ−​R+2.8

jianmo的博客 1211

usaco1.1.3 Friday the Thirteenth黑色星期五

usaco1.1.3  Friday the Thirteenth黑色星期五 题目翻译:http://www.nocow.cn/index.php/Translate:USACO/friday 很简单的模拟题,关键是读清楚题,注意如何判断闰年。/* ID: wsc5001 LANG: C TASK: friday */ #include int runnian(int y) {

wsc500的专栏 526

Cesium实战:如何在前端直接渲染TIFF影像(附完整代码与避坑指南)

本文详细介绍了如何在前端利用Cesium直接加载和渲染TIFF影像的完整技术方案。针对TIFF格式的地理影像数据,文章提供了从文件解析、坐标转换到像素处理与Cesium集成的全流程代码实现,并分享了性能优化与常见问题的避坑指南,帮助开发者高效实现三维地理可视化。

weixin_29290947的博客 314

HIDL概述

HIDL背景 Treble 是 Google Android 团队的一项重大项目,意在 Android 操作系统框架在架构方面的一项重大改变,旨在让制造商以更低的成本更轻松、更快速地将设备更新到新版 Android 系统。Android 7.x 及更早版本中没有正式的供应商接口,因此设备制造商必须更新大量 Android 代码才能将设备更新到新版 Android 系统: 图1 Treble ...

u013357557的专栏 2万+

USACO之Friday the Thirteenth

这道题只要模拟就行了,求出每个月13日是星期几,然后汇总,输出即可(注意输出顺序!) 求每个月13日是星期几,可以用递推的方法。首先先记录上个月13日是多少天,再计算从上个月13日到这个月13日有几天,这样这个月13日是星期几就很好求出了,而且速度很快。 废话少说,代码上: #include #include #include static int currentDay = -18;

wrz918的专栏 410

DeepSeek R1-32B医疗大模型的完整微调实战分析(全码版)

【代码】DeepSeek R1-32B医疗大模型的完整微调实战指南(全码版)

AllenLV的博客 5101

USACO Friday the Thirteenth

/* ID: fan19132 PROG: friday LANG: C++ */ #include"stdio.h" #include"string.h" struct person{ char name[20]; int money; }persons[15]; int leap_month_day[13]={0,31,29,31,30,31,30,31,31,30,31,30

不要挡住我的阳光 434

CATIA二次开发——遍历几何图形集下的轴系及控制轴系生成位置

CATIA二次开发——轴系相关问题1.遍历几何图形集下的轴系2.解决轴系生成位置的问题 1.遍历几何图形集下的轴系 近期遇到的问题:遍历轴系的时候发现,AxisSystem属性的轴系只有放在轴系集合下,才能被找到,放在几何图形集或其他位置均不能被找到。本来想遍历几何图形集下的轴系元素,但是发现没有对应的属性,只能查找 几何图形集、几何元素、草图等元素,无法直接遍历轴系。 解决办法:(加入选择集,在选择集中筛选轴系类型) HybridBody axisHB = activePart.HybridBodies

WorkMan的博客 2730

SAP FICO 内部往来对账功能开发说明书(包括测试样例、程序代码仅作参考,不保证一定可以运行)

SAP FICO 内部往来对账功能开发说明书(包括开发源代码、测试样例、FS)

我好像病了的博客 1222

USACO天梯--Friday the Thirteenth

USACO Friday the Thirteenth

社畜のブログ 434

VC中sqlite的使用

在VC中对sqlite的使用,实现数据库大批数据的快速插入,读取数据库中的数据在ListCtrl中显示

USACO Friday the Thirteenth 解题日志

在USACO的第三题~ 好久没有做题了的感觉。这几天在家里睡得好爽。。。 不得不说,这也是一道水题。 题目是这样子的: Friday the Thirteenth Is Friday the 13th really an unusual event? That is, does the 13th of the month land on a Friday

菜鸟の小窝 800

华为的C语言编程规范.pdf

华为技术有限公司内部技术规范。本规范制定了编写C语言程序的基本原则、规则和建议。从代码的清晰、简洁、可测试、安全、程序效率、可移植各个方面对C语言编程作出了具体指导。

IEM模型,地表粗糙度模拟

利用微波反演土壤水分时候,利用IEM模型可以实现对随机地表的模拟

USACO--Friday the Thirteenth

Friday the Thirteenth Is Friday the 13th really an unusual event? That is, does the 13th of the month land on a Friday less often than on any other day of the week? To answer this question,

likilli的博客 359

ssm框架搭建

这个是一个在idea上成功跑起来的ssm框架项目,保存在这里方便以后使用直接下载

上一篇: Greedy Gift Givers
下一篇: Broken Necklace
Slatter
博客等级 码龄8年 104粉丝 128原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值