c/c++语言开发共享Ural 1201 Which Day Is It? 题解

Ural 1201 Which Day Is It? 题解 [TOC] 题意 打印一个月历。 输入 输入日$(1sim31)$、月$(1sim12)$、年$(1600sim2400)$。 输出 打印$7$行,”mon””tue”…这些都懂吧。在输入的那天打上[]。 Tips: 1. 样例输 …

目录

  • ural 1201 which day is it? 题解

ural 1201 which day is it? 题解

题意

打印一个月历。

输入

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

输出

输入: 16 3 2002 输出: mon........4...11...18...25 tue........5...12...19...26 wed........6...13...20...27 thu........7...14...21...28 fri...1....8...15...22...29 sat...2....9..[16]..23...30 sun...3...10...17...24...31
输入: 1 3 2002 输出: mon........4...11...18...25 tue........5...12...19...26 wed........6...13...20...27 thu........7...14...21...28 fri.[.1]...8...15...22...29 sat...2....9...16...23...30 sun...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...31 wed........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 <bits/stdc++.h> #include <map> #include <set> #include <list> #include <array> #include <cfenv> #include <cmath> #include <ctime> #include <deque> #include <mutex> #include <queue> #include <ratio> #include <regex> #include <stack> #include <tuple> #include <atomic> #include <bitset> #include <cctype> #include <cerrno> #include <cfloat> #include <chrono> #include <cstdio> #include <cwchar> #include <future> #include <limits> #include <locale> #include <memory> #include <random> #include <string> #include <thread> #include <vector> #include <cassert> #include <climits> #include <clocale> #include <complex> #include <csetjmp> #include <csignal> #include <cstdarg> #include <cstddef> #include <cstdint> #include <cstdlib> #include <cstring> #include <ctgmath> #include <cwctype> #include <fstream> #include <iomanip> #include <numeric> #include <sstream> #include <ccomplex> #include <cstdbool> #include <iostream> #include <typeinfo> #include <valarray> #include <algorithm> #include <cinttypes> #include <cstdalign> #include <stdexcept> #include <typeindex> #include <functional> #include <forward_list> #include <system_error> #include <unordered_map> #include <unordered_set> #include <scoped_allocator> #include <condition_variable> // #include <conio.h> // #include <windows.h> 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<int,int> 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<<setprecision(n)  const int inf=1061109567; const int ninf=-1044266559; const ll linf=4557430888798830399; const ld eps=1e-15; #define mod (1000000007) #define pi (3.1415926535897932384626433832795028841971)  /* #define mb_len_max 5 #define shrt_min (-32768) #define shrt_max 32767 #define ushrt_max 0xffffu #define int_min (-2147483647 - 1) #define int_max 2147483647 #define uint_max 0xffffffffu #define long_min (-2147483647l - 1) #define long_max 2147483647l #define ulong_max 0xfffffffful #define llong_max 9223372036854775807ll #define llong_min (-9223372036854775807ll - 1) #define ullong_max 0xffffffffffffffffull */  #define mp make_pair #define mt make_tuple #define all(a) (a).begin(),(a).end() #define pall(a) (a).rbegin(),(a).rend() #define log2(x) log(x)/log(2) #define log(x,y) log(x)/log(y) #define sz(a) ((int)(a).size()) #define rep(i,n) for(int i=0;i<((int)(n));i++) #define rep1(i,n) for(int i=1;i<=((int)(n));i++) #define repa(i,a,n) for(int i=((int)(a));i<((int)(n));i++) #define repa1(i,a,n) for(int i=((int)(a));i<=((int)(n));i++) #define repd(i,n) for(int i=((int)(n))-1;i>=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 printf  inline 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 => mon  inline 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<m2; else return y1<y2; }  inline int getweek(int year,int month) {     int y=1,m=1,w=0;     while(y!=year||m!=month)     {         if(cmp(y,m,year,month))         {             w=(w+getday(y,m)%7)%7;              m++;             if(m==13)             {                 y++;                 m=1;             }         }     }      return w+1; }  inline void print(int year,int month,int day) {     vector<int> 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<<str[i]<<endl; }  int main() {     int year,month,day;     cin>>day>>month>>year;     print(year,month,day);      return 0; } /*************************************************************end**************************************************************/

本文来自网络收集,不代表计算机技术网立场,如涉及侵权请联系管理员删除。

ctvol管理联系方式QQ:251552304

本文章地址:https://www.ctvol.com/c-cdevelopment/602449.html

(0)
上一篇 2021年5月11日
下一篇 2021年5月11日

精彩推荐