1111 对称日 - PAT (Basic Level) Practice (中文) (pintia.cn)
坑点:
year补0的时候要用while不能用if:
因为year给的是1位~4位数,我们必须要把它补齐为四位数
补齐完之后 然后把它们拼接起来,再逆转一下,如果逆转前后一样,说明具有对乘性。
#include<bits/stdc++.h>
using namespace std;
string months[13]={"","Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"};
int main()
{
int n;cin>>n;
string month, day,year;
for(int i=0;i<n;i++)
{
cin>>month>>day>>year;
day.erase(day.end()-1);
//映射
for(int i=0;i<13;i++) //注意这里不能直接用months.size()。因为months[13]是字符串数组,数组没有size()函数
{
if(month==months[i])
month=to_string(i);
}
//补齐
if(month.size()<2)month="0"+month;
if(day.size()<2)day="0"+day;
while(year.size()<4)year="0"+year;
//判断是否是回文串日期
string data=year+month+day;
string temp=data;
reverse(temp.begin(),temp.end());
if(data==temp)cout<<"Y "<<data<<endl;
else cout<<"N "<<data<<endl;
}
return 0;
}