sicily 1125. Arnie versus the IRS
来源:互联网 发布:花生壳 免费 域名 流量 编辑:程序博客网 时间:2024/05/29 02:32
1125. Arnie versus the IRS
Constraints
Time Limit: 10 secs, Memory Limit: 32 MB
Description
Arnie’s bakery is the leading producer of gourmet dog treats in the world. To comply with FDA requirements, Arnie etches the current date on each treat he produces. The date is etched using the format YYYYMMDD, where YYYY represents the year, MM represents the month, and DD represents the date (these values are padded with zeros if necessary). Arnie is very particular about the work that he does, and takes his time making treats, and as a result he only produces one treat a day.
The IRS has been after Arnie for some time, and this year they have decided to audit him. After working with the auditor for several days, the only remaining bone of contention is the writeoff that Arnie claims for etching the date on his products. In order to satisfy the auditor, and get back to work, Arnie must determine the number of each of the digits he engraved in his treats during a specific period of time.
For example, during the period 11/01/2004 through 11/02/2004 Arnie produced two treats and etched a total of 6 zeros, 5 ones, 3 twos, and 2 fours.
Input
The input to your program will consist of two lines, each containing a date formatted as MM/DD/YYYY. The first line specifies the start of the period, and the second the end of the period (inclusive). You may assume that the first date occurs before or on the second and that the year in both dates is greater than or equal to 1920.
Output
Your program will produce as output a list that contains two columns. The first column contains the digits 0 to 9, in ascending order. The second column contains the number of times the corresponding digit appeared. Note that Arnie enjoys his free time (he likes to take his humans on long walks in the woods) and therefore does not work on Saturdays and Sundays.
ps. Print a blank line between each test case.
Sample Input
10/31/200411/02/2004
Sample Output
0 61 52 33 04 25 06 07 08 09 0
题目分析
给定两个日期,忽略其中为周末的日期
计算其他日期中所有数字出现的次数(自动补齐为mmddyyyy格式)
先算出起始日期是周几,然后暴力遍历
注意日期加一天的变化
#include <iostream>#include <cstdio>#include <memory.h>std::string wd[7] = {"Wed", "Thur", "Fri", "Sat", "Sun", "Mon", "Tue"};int month[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};int ans[10];bool leap(int year) { if (year % 400 == 0) return true; if (year % 4 == 0 && year % 100 != 0) return true; return false;}int cal(int sd, int sm, int sy) { int day = 0; for (int i = 1920; i < sy; ++i) { if (leap(i)) day += 366; else day += 365; } if (leap(sy)) month[1] = 29; else month[1] = 28; for (int i = 0; i < sm-1; ++i) { day += month[i]; } day += sd; day %= 7; return day;}void add(int m, int d, int y) { int temp; temp = m%10; ans[temp]++; temp = (m-temp)/10; ans[temp]++; temp = d%10; ans[temp]++; temp = (d-temp)/10; ans[temp]++; temp = y%10; ans[temp]++; y = (y-temp)/10; temp = y%10; ans[temp]++; y = (y-temp)/10; temp = y%10; ans[temp]++; y = (y-temp)/10; temp = y%10; ans[temp]++;}int main(){ std::string start, end; bool first = true; while (std::cin >> start >> end) { if (first) first = false; else printf("\n"); memset(ans, 0, sizeof(ans)); int sm = (start[0]-'0')*10+(start[1]-'0'); int sd = (start[3]-'0')*10+(start[4]-'0'); int sy = (start[6]-'0')*1000+(start[7]-'0')*100+(start[8]-'0')*10+(start[9]-'0'); int em = (end[0]-'0')*10+(end[1]-'0'); int ed = (end[3]-'0')*10+(end[4]-'0'); int ey = (end[6]-'0')*1000+(end[7]-'0')*100+(end[8]-'0')*10+(end[9]-'0'); int weekday = cal(sd, sm, sy); //std::cout << wd[weekday] << std::endl; if (weekday != 3 && weekday != 4) { add(sm, sd, sy); } while ( !(sm==em && sd==ed && sy==ey) ) { weekday = weekday!=6 ? weekday+1 : 0; if (leap(sy)) month[1] = 29; else month[1] = 28; if (sd < month[sm-1]) { sd++; } else { sd = 1; if (sm == 12) { sm = 1; sy++; } else { sm++; } } if (weekday!=3 && weekday!=4) { //std::cout << sm << " " << sd << " " << sy << std::endl; add(sm, sd, sy); } } for (int i = 0; i <= 9; ++i) printf("%d %d\n", i, ans[i]); }}
- sicily 1125. Arnie versus the IRS
- Sicily.1125. Arnie versus the IRS(统计时间段内各个数字出现次数,不算周六日)
- The Business Versus the Angry Architect
- <Sicily>Catch the thief
- sicily Catch the thief
- sicily 1231 The Embarrassed Cryptography
- Sicily 1157. The hardest problem
- Sicily 4423. Calculate the Sum
- Sicily 4469. Find the Ball
- sicily--1157. The hardest problem
- Sicily 1193 Up the Stairs
- sicily 1157.The hardest problem
- Sicily 1935. Rebuild the tree
- Sicily 1157. The hardest problem
- Sicily 1193. Up the Stairs
- Sicily 1157 the hardest problem
- sicily 1203. The Cubic End
- sicily 5144 catch the thief
- 秒杀多线程第六篇---经典线程同步 事件Event
- nyoj--914--Yougth的最大化(二分查找)
- webpy源码阅读
- codeforces-441B-Valera and Fruits【暴力】
- 关于平方和立方和,注意范围的取值顺序
- sicily 1125. Arnie versus the IRS
- ios swift UILabel 颜色使用图片
- Job任务的3种实现:java.util.Timer, spring Quartz,spring @scheduled
- BubbleSort
- 606第九周周六赛 G - Calling Extraterrestrial Intelligence Again找最大的两个质数
- Bayer图像的由来及Opencv preview
- create table of mysql database
- Procedure -- 存储过程初体验
- 拖拽表格单元格,改变单元格内容