博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Ural 1201 Which Day Is It? 题解
阅读量:5231 次
发布时间:2019-06-14

本文共 5235 字,大约阅读时间需要 17 分钟。

目录

Ural 1201 Which Day Is It? 题解

题意

打印一个月历。

输入

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

输出

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

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

Tips:

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

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

    例:

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

题解

  1. 找出这一个月的第一天是星期几。
    1. 知道1.1.1(公元元年1月1日)是星期一。
    2. 暴力推一下就可以了。
  2. 打印月历。

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

程序

// #pragma GCC optimize(2)// #pragma G++ optimize(2)// #pragma comment(linker,"/STACK:102400000,102400000")// #include 
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
// #include
// #include
using namespace std;typedef long long LL;typedef unsigned int ui;typedef unsigned long long ull;typedef float fl;typedef double ld;typedef long double LD;typedef pair
pii;#if (WIN32) || (WIN64) || (__WIN32) || (__WIN64) || (_WIN32) || (_WIN64) || (WINDOWS)#define lld "%I64d"#define llu "%I64u"#else#define lld "%lld"#define llu "%llu"#endif#define ui(n) ((unsigned int)(n))#define LL(n) ((long long)(n))#define ull(n) ((unsigned long long)(n))#define fl(n) ((float)(n))#define ld(n) ((double)(n))#define LD(n) ((long double)(n))#define char(n) ((char)(n))#define Bool(n) ((bool)(n))#define fixpoint(n) fixed<
=0;i--)#define repd1(i,n) for(int i=((int)(n));i>=1;i--)#define repda(i,n,a) for(int i=((int)(n));i>((int)(a));i--)#define repda1(i,n,a) for(int i=((int)(n));i>=((int)(a));i--)#define FOR(i,a,n,step) for(int i=((int)(a));i<((int)(n));i+=((int)(step)))#define repv(itr,v) for(__typeof((v).begin()) itr=(v).begin();itr!=(v).end();itr++)#define repV(i,v) for(auto i:v)#define repE(i,v) for(auto &i:v)#define MS(x,y) memset(x,y,sizeof(x))#define MC(x) MS(x,0)#define MINF(x) MS(x,63)#define MCP(x,y) memcpy(x,y,sizeof(y))#define sqr(x) ((x)*(x))#define UN(v) sort(All(v)),v.erase(unique(All(v)),v.end())#define filein(x) freopen(x,"r",stdin)#define fileout(x) freopen(x,"w",stdout)#define fileio(x)\ freopen(x".in","r",stdin);\ freopen(x".out","w",stdout)#define filein2(filename,name) ifstream name(filename,ios::in)#define fileout2(filename,name) ofstream name(filename,ios::out)#define file(filename,name) fstream name(filename,ios::in|ios::out)#define Pause system("pause")#define Cls system("cls")#define fs first#define sc second#define PC(x) putchar(x)#define GC(x) x=getchar()#define Endl PC('\n')#define SF scanf#define PF printfinline int Read(){ 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(); return w?-X:X;}inline void Write(int x){if(x<0)putchar('-'),x=-x;if(x>9)Write(x/10);putchar(x%10+'0');}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;}inline LL gcdll(LL a,LL b){return b?gcdll(b,a%b):a;}const int dx[]={0,1,0,-1,1,-1,-1,1};const int dy[]={1,0,-1,0,-1,-1,1,1};/************************************************************Begin************************************************************/const int maxn=INF;const int days[]={0,31,0,31,30,31,30,31,31,30,31,30,31};const string weeks[]={"","mon","tue","wed","thu","fri","sat","sun"};// 1.1.1 => moninline int getday(int year,int month){ if(month==2) { if(year%400==0) return 29; if(year%100==0) return 28; return year%4==0?29:28; } else return days[month];}inline bool cmp(int y1,int m1,int y2,int m2){ if(y1==y2) return m1
w[8]; int lst=getweek(year,month); w[lst].push_back(1); rep1(i,lst-1) w[i].push_back(0); int pos[15]; pos[0]=6; rep1(i,5) pos[i]=pos[i-1]+5; repa1(i,2,getday(year,month)) { lst++; if(lst==8) lst=1; w[lst].push_back(i); } string str[8]; rep1(i,7) { str[i]=weeks[i]; rep(j,100) str[i]+=" "; rep(j,w[i].size()) { int x=w[i][j]; if(x) str[i][pos[j]]=(x%10+'0'); if(x/10) str[i][pos[j]-1]=(x/10+'0'); if(x==day) { str[i][pos[j]-2]='['; str[i][pos[j]+1]=']'; } } } rep1(i,7) cout<
<
>day>>month>>year; print(year,month,day); return 0;}/*************************************************************End**************************************************************/

转载于:https://www.cnblogs.com/bitstd/p/11294027.html

你可能感兴趣的文章
Azure SQL 数据库弹性池现已面市
查看>>
基于visual Studio2013解决面试题之1105字符串压缩
查看>>
LaTeX技巧007:每一章开始的header引用名言应该怎么做?
查看>>
[LeetCode] Find Bottom Left Tree Value
查看>>
[Algorithm] Bloom Filter
查看>>
[LeetCode] Lexicographical Numbers
查看>>
报错:java.net.bindexception: address already in use: jvm_bind:8080
查看>>
【最新】最流行的java后台框架 springmvc mybaits 集代码生成器 SSM SSH
查看>>
正则表达式入门
查看>>
VS2008连接TFS2010的安装说明
查看>>
JSP底层方法的封装
查看>>
关于comparator接口和comparable接口以及它们各自的方法compare()和compareTo()
查看>>
remotepath != null 与 !TextUtils.isEmpty(remotepath) 的差别
查看>>
DropdownList绑定的两种方法
查看>>
java final keyword
查看>>
muduo网络图书馆评测
查看>>
A - I Wanna Be the Guy
查看>>
NYOJ 239 月老的难题
查看>>
数据库转移碰到的问题
查看>>
12个值得关注的顶级可视化JS库 涉及图表、动画、时间处理,表格操作
查看>>