一【题目描述】
二【题目样例】
三【解题思路】
1.注意这里补0的情况,因为有可能输入年份为1,就要变为0001
while(day.size()<2){
day="0"+day;
}
while(year.size()<4){
year="0"+year;
}
2.reverse()的头文件为#include<algorithm>
reverse(str.begin(),str.end()) 处理字符串时,翻转整个字符串
四【代码实现】
#include<cstdio>
#include<math.h>
#include<string.h>
#include<string>
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
int n;scanf("%d",&n);
for(int i=0;i<n;i++){
string month,day,year;
cin>>month>>day>>year;
if(month=="Feb"){
month="02";
}
if(month=="Jan"){
month="01";
}
if(month=="Mar"){
month="03";
}
if(month=="Apr"){
month="04";
}
if(month=="May"){
month="05";
}
if(month=="Jun"){
month="06";
}
if(month=="Jul"){
month="07";
}
if(month=="Aug"){
month="08";
}
if(month=="Sep"){
month="09";
}
if(month=="Oct"){
month="10";
}
if(month=="Nov"){
month="11";
}
if(month=="Dec"){
month="12";
}
day=day.substr(0,day.size()-1);
while(day.size()<2){
day="0"+day;
}
while(year.size()<4){
year="0"+year;
}
string res=year+month+day;
string rres=res;
reverse(rres.begin(),rres.end());//反转整个字符串
if(rres!=res){
cout<<"N "<<res<<endl;
}
else{
cout<<"Y "<<res<<endl;;
}
}
}