现在做网站建设挣钱吗,网站索引查询,建设工程招聘网,云落 wordpress主题央视新闻发了一条微博#xff0c;指出 2020 年有个罕见的“对称日”#xff0c;即 2020 年 2 月 2 日#xff0c;按照 年年年年月月日日 格式组成的字符串 20200202 是完全对称的。
给定任意一个日期#xff0c;本题就请你写程序判断一下#xff0c;这是不是一个对称日指出 2020 年有个罕见的“对称日”即 2020 年 2 月 2 日按照 年年年年月月日日 格式组成的字符串 20200202 是完全对称的。
给定任意一个日期本题就请你写程序判断一下这是不是一个对称日
输入格式
输入首先在第一行给出正整数 N1N≤10。随后 N 行每行给出一个日期却是按英文习惯的格式Month Day, Year。其中 Month 是月份的缩写对应如下
一月Jan二月Feb三月Mar四月Apr五月May六月Jun七月Jul八月Aug九月Sep十月Oct十一月Nov十二月Dec
Day 是月份中的日期为 [1, 31] 区间内的整数Year 是年份为 [1, 9999] 区间内的整数。
输出格式
对每一个给定的日期在一行中先输出 Y 如果这是一个对称日否则输出 N随后空一格输出日期对应的 年年年年月月日日 格式组成的字符串。
输入样例
5
Feb 2, 2020
Mar 7, 2020
Oct 10, 101
Nov 21, 1211
Dec 29, 1229输出样例
Y 20200202
N 20200307
Y 01011010
Y 12111121
N 12291229 解析输入是月日年而且需要忽略一下日的逗号然后拼接字符的时候注意月日要补齐2位年要补齐4位。
#include bits/stdc.h
using namespace std;
bool check(string a)//判断是否是回文串
{string ba;reverse(b.begin(),b.end());//反转if(ab) return true;return false;
}
void solve()
{string year,month,day,target;cinmonthdayyear;targetyear;while(target.size()4) target0target;//补齐4位if(monthJan) month01;else if(monthFeb) month02;else if(monthMar) month03;else if(monthApr) month04;else if(monthMay) month05;else if(monthJun) month06;else if(monthJul) month07;else if(monthAug) month08;else if(monthSep) month09;else if(monthOct) month10;else if(monthNov) month11;else if(monthDec) month12;targetmonth;if(day.size()2) day0day;//补齐2位数值for(int i0;i2;i) targetday[i];//忽视逗号取前两位if(check(target)) coutY targetendl;//是回文字符串else coutN targetendl;
}
int main()
{int t;scanf(%d,t);while(t--) solve();return 0;
}