Ural 1201 Which Day Is It? 题解

题意

打印一个月历。

输入

输入日\((1\sim31)\)、月\((1\sim12)\)、年\((1600\sim2400)\)。

输出

  1. 输入: 16 3 2002
  2. 输出:
  3. mon........4...11...18...25
  4. tue........5...12...19...26
  5. wed........6...13...20...27
  6. thu........7...14...21...28
  7. fri...1....8...15...22...29
  8. sat...2....9..[16]..23...30
  9. sun...3...10...17...24...31
  1. 输入: 1 3 2002
  2. 输出:
  3. mon........4...11...18...25
  4. tue........5...12...19...26
  5. wed........6...13...20...27
  6. thu........7...14...21...28
  7. fri.[.1]...8...15...22...29
  8. sat...2....9...16...23...30
  9. sun...3...10...17...24...31

打印\(7\)行,"mon""tue"...这些都懂吧。在输入的那天打上[]。

Tips:

  1. 样例输出中的'\(.\)'其实是' '(空格)。

  2. 输出的第一列日期前有三个'\(.\)',第二列即以后一位数前有\(4\)个,两位数前有\(3\)个。

    例:

    1. 输入: 30 1 2012
    2. 输出:
    3. mon........2....9...16...23..[30]
    4. tue........3...10...17...24...31
    5. wed........4...11...18...25.....
    6. thu........5...12...19...26.....
    7. fri........6...13...20...27.....
    8. sat........7...14...21...28.....
    9. sun...1....8...15...22...29.....
  3. 如果输入的那一天是个一位数,则打印\([.x]\)。

题解

  1. 找出这一个月的第一天是星期几。

    1. 知道1.1.1(公元元年1月1日)是星期一。
    2. 暴力推一下就可以了。
  2. 打印月历。

Tip: 口胡得很简单,写起来可能有点麻烦,要仔细。

程序

  1. // #pragma GCC optimize(2)
  2. // #pragma G++ optimize(2)
  3. // #pragma comment(linker,"/STACK:102400000,102400000")
  4. // #include <bits/stdc++.h>
  5. #include <map>
  6. #include <set>
  7. #include <list>
  8. #include <array>
  9. #include <cfenv>
  10. #include <cmath>
  11. #include <ctime>
  12. #include <deque>
  13. #include <mutex>
  14. #include <queue>
  15. #include <ratio>
  16. #include <regex>
  17. #include <stack>
  18. #include <tuple>
  19. #include <atomic>
  20. #include <bitset>
  21. #include <cctype>
  22. #include <cerrno>
  23. #include <cfloat>
  24. #include <chrono>
  25. #include <cstdio>
  26. #include <cwchar>
  27. #include <future>
  28. #include <limits>
  29. #include <locale>
  30. #include <memory>
  31. #include <random>
  32. #include <string>
  33. #include <thread>
  34. #include <vector>
  35. #include <cassert>
  36. #include <climits>
  37. #include <clocale>
  38. #include <complex>
  39. #include <csetjmp>
  40. #include <csignal>
  41. #include <cstdarg>
  42. #include <cstddef>
  43. #include <cstdint>
  44. #include <cstdlib>
  45. #include <cstring>
  46. #include <ctgmath>
  47. #include <cwctype>
  48. #include <fstream>
  49. #include <iomanip>
  50. #include <numeric>
  51. #include <sstream>
  52. #include <ccomplex>
  53. #include <cstdbool>
  54. #include <iostream>
  55. #include <typeinfo>
  56. #include <valarray>
  57. #include <algorithm>
  58. #include <cinttypes>
  59. #include <cstdalign>
  60. #include <stdexcept>
  61. #include <typeindex>
  62. #include <functional>
  63. #include <forward_list>
  64. #include <system_error>
  65. #include <unordered_map>
  66. #include <unordered_set>
  67. #include <scoped_allocator>
  68. #include <condition_variable>
  69. // #include <conio.h>
  70. // #include <windows.h>
  71. using namespace std;
  72. typedef long long LL;
  73. typedef unsigned int ui;
  74. typedef unsigned long long ull;
  75. typedef float fl;
  76. typedef double ld;
  77. typedef long double LD;
  78. typedef pair<int,int> pii;
  79. #if (WIN32) || (WIN64) || (__WIN32) || (__WIN64) || (_WIN32) || (_WIN64) || (WINDOWS)
  80. #define lld "%I64d"
  81. #define llu "%I64u"
  82. #else
  83. #define lld "%lld"
  84. #define llu "%llu"
  85. #endif
  86. #define ui(n) ((unsigned int)(n))
  87. #define LL(n) ((long long)(n))
  88. #define ull(n) ((unsigned long long)(n))
  89. #define fl(n) ((float)(n))
  90. #define ld(n) ((double)(n))
  91. #define LD(n) ((long double)(n))
  92. #define char(n) ((char)(n))
  93. #define Bool(n) ((bool)(n))
  94. #define fixpoint(n) fixed<<setprecision(n)
  95. const int INF=1061109567;
  96. const int NINF=-1044266559;
  97. const LL LINF=4557430888798830399;
  98. const ld eps=1e-15;
  99. #define MOD (1000000007)
  100. #define PI (3.1415926535897932384626433832795028841971)
  101. /*
  102. #define MB_LEN_MAX 5
  103. #define SHRT_MIN (-32768)
  104. #define SHRT_MAX 32767
  105. #define USHRT_MAX 0xffffU
  106. #define INT_MIN (-2147483647 - 1)
  107. #define INT_MAX 2147483647
  108. #define UINT_MAX 0xffffffffU
  109. #define LONG_MIN (-2147483647L - 1)
  110. #define LONG_MAX 2147483647L
  111. #define ULONG_MAX 0xffffffffUL
  112. #define LLONG_MAX 9223372036854775807ll
  113. #define LLONG_MIN (-9223372036854775807ll - 1)
  114. #define ULLONG_MAX 0xffffffffffffffffull
  115. */
  116. #define MP make_pair
  117. #define MT make_tuple
  118. #define All(a) (a).begin(),(a).end()
  119. #define pall(a) (a).rbegin(),(a).rend()
  120. #define log2(x) log(x)/log(2)
  121. #define Log(x,y) log(x)/log(y)
  122. #define SZ(a) ((int)(a).size())
  123. #define rep(i,n) for(int i=0;i<((int)(n));i++)
  124. #define rep1(i,n) for(int i=1;i<=((int)(n));i++)
  125. #define repa(i,a,n) for(int i=((int)(a));i<((int)(n));i++)
  126. #define repa1(i,a,n) for(int i=((int)(a));i<=((int)(n));i++)
  127. #define repd(i,n) for(int i=((int)(n))-1;i>=0;i--)
  128. #define repd1(i,n) for(int i=((int)(n));i>=1;i--)
  129. #define repda(i,n,a) for(int i=((int)(n));i>((int)(a));i--)
  130. #define repda1(i,n,a) for(int i=((int)(n));i>=((int)(a));i--)
  131. #define FOR(i,a,n,step) for(int i=((int)(a));i<((int)(n));i+=((int)(step)))
  132. #define repv(itr,v) for(__typeof((v).begin()) itr=(v).begin();itr!=(v).end();itr++)
  133. #define repV(i,v) for(auto i:v)
  134. #define repE(i,v) for(auto &i:v)
  135. #define MS(x,y) memset(x,y,sizeof(x))
  136. #define MC(x) MS(x,0)
  137. #define MINF(x) MS(x,63)
  138. #define MCP(x,y) memcpy(x,y,sizeof(y))
  139. #define sqr(x) ((x)*(x))
  140. #define UN(v) sort(All(v)),v.erase(unique(All(v)),v.end())
  141. #define filein(x) freopen(x,"r",stdin)
  142. #define fileout(x) freopen(x,"w",stdout)
  143. #define fileio(x)\
  144. freopen(x".in","r",stdin);\
  145. freopen(x".out","w",stdout)
  146. #define filein2(filename,name) ifstream name(filename,ios::in)
  147. #define fileout2(filename,name) ofstream name(filename,ios::out)
  148. #define file(filename,name) fstream name(filename,ios::in|ios::out)
  149. #define Pause system("pause")
  150. #define Cls system("cls")
  151. #define fs first
  152. #define sc second
  153. #define PC(x) putchar(x)
  154. #define GC(x) x=getchar()
  155. #define Endl PC('\n')
  156. #define SF scanf
  157. #define PF printf
  158. inline int Read()
  159. {
  160. int X=0,w=0;char ch=0;while(!isdigit(ch)){w|=ch=='-';ch=getchar();}while(isdigit(ch))X=(X<<3)+(X<<1)+(ch^48),ch=getchar();
  161. return w?-X:X;
  162. }
  163. inline void Write(int x){if(x<0)putchar('-'),x=-x;if(x>9)Write(x/10);putchar(x%10+'0');}
  164. inline LL powmod(LL a,LL b){LL RES=1;a%=MOD;assert(b>=0);for(;b;b>>=1){if(b&1)RES=RES*a%MOD;a=a*a%MOD;}return RES%MOD;}
  165. inline LL gcdll(LL a,LL b){return b?gcdll(b,a%b):a;}
  166. const int dx[]={0,1,0,-1,1,-1,-1,1};
  167. const int dy[]={1,0,-1,0,-1,-1,1,1};
  168. /************************************************************Begin************************************************************/
  169. const int maxn=INF;
  170. const int days[]={0,31,0,31,30,31,30,31,31,30,31,30,31};
  171. const string weeks[]={"","mon","tue","wed","thu","fri","sat","sun"};
  172. // 1.1.1 => mon
  173. inline int getday(int year,int month)
  174. {
  175. if(month==2)
  176. {
  177. if(year%400==0) return 29;
  178. if(year%100==0) return 28;
  179. return year%4==0?29:28;
  180. }
  181. else return days[month];
  182. }
  183. inline bool cmp(int y1,int m1,int y2,int m2)
  184. {
  185. if(y1==y2) return m1<m2; else return y1<y2;
  186. }
  187. inline int getweek(int year,int month)
  188. {
  189. int y=1,m=1,w=0;
  190. while(y!=year||m!=month)
  191. {
  192. if(cmp(y,m,year,month))
  193. {
  194. w=(w+getday(y,m)%7)%7;
  195. m++;
  196. if(m==13)
  197. {
  198. y++;
  199. m=1;
  200. }
  201. }
  202. }
  203. return w+1;
  204. }
  205. inline void print(int year,int month,int day)
  206. {
  207. vector<int> w[8];
  208. int lst=getweek(year,month);
  209. w[lst].push_back(1);
  210. rep1(i,lst-1) w[i].push_back(0);
  211. int pos[15];
  212. pos[0]=6;
  213. rep1(i,5) pos[i]=pos[i-1]+5;
  214. repa1(i,2,getday(year,month))
  215. {
  216. lst++;
  217. if(lst==8) lst=1;
  218. w[lst].push_back(i);
  219. }
  220. string str[8];
  221. rep1(i,7)
  222. {
  223. str[i]=weeks[i];
  224. rep(j,100) str[i]+=" ";
  225. rep(j,w[i].size())
  226. {
  227. int x=w[i][j];
  228. if(x) str[i][pos[j]]=(x%10+'0');
  229. if(x/10) str[i][pos[j]-1]=(x/10+'0');
  230. if(x==day)
  231. {
  232. str[i][pos[j]-2]='[';
  233. str[i][pos[j]+1]=']';
  234. }
  235. }
  236. }
  237. rep1(i,7) cout<<str[i]<<endl;
  238. }
  239. int main()
  240. {
  241. int year,month,day;
  242. cin>>day>>month>>year;
  243. print(year,month,day);
  244. return 0;
  245. }
  246. /*************************************************************End**************************************************************/

Ural 1201 Which Day Is It? 题解的更多相关文章

  1. URAL 1932 The Secret of Identifier 题解

    http://acm.timus.ru/problem.aspx?space=1&num=1932 B - The Secret of Identifier Time Limit:1000MS ...

  2. URAL题解三

    URAL题解三 URAL 1045 题目描述:有\(n\)个机场,\(n-1\)条航线,任意两个机场有且只有一种方案联通.现有两个恐怖分子从\(m\)号机场出发,第一个人在机场安装炸弹,乘坐飞机,引爆 ...

  3. URAL题解二

    URAL题解二 URAL 1082 题目描述:输出程序的输入数据,使得程序输出"Beutiful Vasilisa" solution 一开始只看程序的核心部分,发现是求快排的比较 ...

  4. URAL题解一

    URAL题解一 URAL 1002 题目描述:一种记住手机号的方法就是将字母与数字对应,如图.这样就可以只记住一些单词,而不用记住数字.给出一个数字串和n个单词,用最少的单词数来代替数字串,输出对应的 ...

  5. Ural 1029 Ministry 题解

    目录 Ural 1029 Ministry 题解 题意 题解 程序 Ural 1029 Ministry 题解 题意 给定一个\(n\times m(1\le n \le10,1\le m \le50 ...

  6. Ural 1298 Knight 题解

    目录 Ural 1298 Knight 题解 题意 题解 程序 Ural 1298 Knight 题解 题意 给定一个\(n\times n(1\le n\le8)\)的国际象棋棋盘和一个骑士(基本上 ...

  7. Ural 1238 Folding 题解

    目录 Ural 1238 Folding 题解 题意 题解 程序 Ural 1238 Folding 题解 题意 定义折叠.展开为: 单个大写英文字母是一个折叠的串,把它展开后是它本身. 如果\(S\ ...

  8. Ural 1248 Sequence Sum 题解

    目录 Ural 1248 Sequence Sum 题解 题意 题解 程序 Ural 1248 Sequence Sum 题解 题意 给定\(n\)个用科学计数法表示的实数\((10^{-100}\s ...

  9. Ural 1250 Sea Burial 题解

    目录 Ural 1250 Sea Burial 题解 题意 输入 题解 程序 Ural 1250 Sea Burial 题解 题意 给定一个\(n\times m\)的地图,\(.\)为水,\(\#\ ...

随机推荐

  1. c实现单向链表

    实现一个单向链表的:创建.插入.删除.排序(冒泡).逆向.搜索中间节点 #include <iostream> #include <stdio.h> #include < ...

  2. SpringMVC 指定404、500错误页面

    1.在web.xml中追加 <error-page> <error-code>404</error-code> <location>/404</l ...

  3. django中安装pillow ValueError: zlib is required unless explicitly disabled using --disable-zlib, aborting

    在windows系统上,使用  pip install pillow安装pillow时 报错 在使用 easy_install Pillow 方式安装成功,默认是最高版本 如果需要在安装时,指定安装版 ...

  4. 经典算法:n个人围成一圈,报m的离开,最后剩下谁?

    public int remainPersonNumber(int n, int m) { //输入不合法 if(n < 1 || m < 1) return -1; //初始化,存入Li ...

  5. spring 事务-使用@Transactional 注解(事务隔离级别)

    转: spring 事务-使用@Transactional 注解(事务隔离级别) 2016年08月11日 21:49:20 华华鱼 阅读数 15490 标签: spring事务Transactiona ...

  6. 13Flutter页面布局 Wrap组件

    /* Flutter页面布局Wrap组件: Wrap可以实现流布局,单行的Wrap跟Row表现几乎一致,单列的Wrap则跟Row表现几乎一致. 但Row与Column都是单行单列的.Wrap则突破了这 ...

  7. 我的dbtreeview–treeview直接连接数据表_delphi教程

    unit Unit1; interface uses  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs ...

  8. kubernetes之StatefulSet部署zk和kafka

    前提 至少需要三个node节点,否则修改亲和性配置 如果外部访问,需要自己暴露 需要有个storageClass,这样做的原因是避免手动创建pv了 部署zk和kafka 参考: https://www ...

  9. CockroachDB学习笔记——[译]为什么Go语言是CockroachDB的正确选择

    原文链接:https://www.cockroachlabs.com/blog/why-go-was-the-right-choice-for-cockroachdb/ 原作者:Jessica Edw ...

  10. js 高级程序设计 第三章学习笔记——Number数据类型需要注意的事项

    1.浮点数值 虽然小数点前面可以没有整数,但是并不推荐这种写法. 由于保存浮点数值需要的内存空间是保存整数值的两倍,因此ECMAScript会不失时机地将浮点数值转化为整数数值.显然,如果小数点后面没 ...