PAT--1111 对称日

央视新闻发了一条微博,指出 2020 年有个罕见的“对称日”,即 2020 年 2 月 2 日,按照 年年年年月月日日 格式组成的字符串 20200202 是完全对称的。

给定任意一个日期,本题就请你写程序判断一下,这是不是一个对称日?

输入格式:

输入首先在第一行给出正整数 N(1<N≤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 b=a;
	reverse(b.begin(),b.end());//反转
	if(a==b) return true;
	return false;
}
void solve()
{
	string year,month,day,target;
	cin>>month>>day>>year;
	target=year;
	while(target.size()<4) target="0"+target;//补齐4位
	if(month=="Jan") month="01";
	else if(month=="Feb") month="02";
	else if(month=="Mar") month="03";
	else if(month=="Apr") month="04";
	else if(month=="May") month="05";
	else if(month=="Jun") month="06";
	else if(month=="Jul") month="07";
	else if(month=="Aug") month="08";
	else if(month=="Sep") month="09";
	else if(month=="Oct") month="10";
	else if(month=="Nov") month="11";
	else if(month=="Dec") month="12";
	target+=month;
	if(day.size()==2) day="0"+day;//补齐2位数值
	for(int i=0;i<2;i++) target+=day[i];//忽视逗号,取前两位
	if(check(target)) cout<<"Y "<<target<<endl;//是回文字符串
	else cout<<"N "<<target<<endl;
}
int main()
{
	int t;
	scanf("%d",&t);
	while(t--) solve();
	return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值