这个题其实不难,主要思想是转化月份,但是这个题有个瓶颈,就是输入的时候里面有个逗号,如果是c语言用scanf可以很轻松的解决,但是使用c++的话却不能直接加逗号,后来,我在网上搜了一下,可以引用cin.get(),这个c++内置函数可以输入任意一个单个字符。话不多说,上代码
#include<bits/stdc++.h>
using namespace std;
int main()
{
int n, i, year[10], day[10], m[10], y[10], d[10];
string month[10];
cin >> n;
for(i = 0; i < n; i++)
{
cin >> month[i] >> day[i];
cin.get();
cin >> year[i];
if(month[i] == "Jan")
{
m[0] = 0;
m[1] = 1;
}
else if(month[i] == "Feb")
{
m[0] = 0;
m[1] = 2;
}
else if(month[i] == "Mar")
{
m[0] = 0;
m[1] = 3;
}
else if(month[i] == "Apr")
{
m[0] = 0;
m[1] = 4;
}
else if(month[i] == "May")
{
m[0] = 0;
m[1] = 5;
}
else if(month[i] == "Jun")
{
m[0] = 0;
m[1] = 6;
}
else if(month[i] == "Jul")
{
m[0] = 0;
m[1] = 7;
}
else if(month[i] == "Aug")
{
m[0] = 0;
m[1] = 8;
}
else if(month[i] == "Sep")
{
m[0] = 0;
m[1] = 9;
}
else if(month[i] == "Oct")
{
m[0] = 1;
m[1] = 0;
}
else if(month[i] == "Nov")
{
m[0] = 1;
m[1] = 1;
}
else if(month[i] == "Dec")
{
m[0] = 1;
m[1] = 2;
}
if(year[i] < 1000 && year[i] >= 100)
{
y[0] = 0;
y[1] = year[i] / 100;
y[2] = year[i] / 10 % 10;
y[3] = year[i] % 10;
}
else if(year[i] >= 1000)
{
y[0] = year[i] / 1000;
y[1] = year[i] / 100 % 10;
y[2] = year[i] / 10 % 10;
y[3] = year[i] % 10;
}
else if(year[i] < 100 && year[i] >= 10)
{
y[0] = 0;
y[1] = 0;
y[2] = year[i] / 10;
y[3] = year[i] % 10;
}
else if(year[i] < 10)
{
y[0] = 0;
y[1] = 0;
y[2] = 0;
y[3] = year[i];
}
if(day[i] < 10)
{
d[0] = 0;
d[1] = day[i];
}
else if(day[i] >= 10)
{
d[0] = day[i] / 10;
d[1] = day[i] % 10;
}
if(y[0] == d[1] && y[1] == d[0] && y[2] == m[1] && y[3] == m[0])
{
printf("Y ");
printf("%04d%d%d%02d\n", year[i], m[0], m[1], day[i]);
}
else
{
printf("N ");
printf("%04d%d%d%02d\n", year[i], m[0], m[1], day[i]);
}
}
}