阿里云超级码力第四场-闰年
代码写的比较丑,就是感觉这题有点意思。如果可以判断第二年是闰年,前一年一定是平年。
int day_diff(int year_start, int month_start, int day_start
, int year_end, int month_end, int day_end)
{
int y2, m2, d2;
int y1, m1, d1;
m1 = (month_start + 9) % 12;
y1 = year_start - m1/10;
d1 = 365*y1 + y1/4 - y1/100 + y1/400 + (m1*306 + 5)/10 + (day_start - 1);
m2 = (month_end + 9) % 12;
y2 = year_end - m2/10;
d2 = 365*y2 + y2/4 - y2/100 + y2/400 + (m2*306 + 5)/10 + (day_end - 1);
return (d2 - d1);
}
string guessYear(vector<vector<int> > &inputQueries) {
// write your code here
string ans="";
for(int i=0;i<inputQueries.size();i++){
int m1=inputQueries[i][0];int d1=inputQueries[i][1];
int m2=inputQueries[i][2];int d2=inputQueries[i][3];
int x=inputQueries[i][4];
if(m1==2&&d1==29){
ans+="R";
continue;
}
if(m1<m2){//一年之中
if(m2==2&&d2==29){
ans+="R";
continue;
}
if(m1>2||m2<=2){
ans+="?";
continue;
}
if(day_diff(2016,m1,d1,2016,m2,d2)==x){
ans+="R";
continue;
}
else{
ans+="P";
continue;
}
}
else if(m1==m2&&d1<=d2){//一年之中
if(m2==2&&d2==29){
ans+="R";
continue;
}
else{
ans+="?";
continue;
}
}
else {//非一年之内
if(m2==2&&d2==29){
ans+="P";
continue;
}
if(m1<=2){
if(day_diff(2016,m1,d1,2017,m2,d2)==x){
ans+="R";
continue;
}
else{
ans+="P";
continue;
}
}
if(m2>2){
if(day_diff(2015,m1,d1,2016,m2,d2)==x){
ans+="P";
continue;
}
}
ans+="?";
continue;
}
}
return ans;
}
不疯魔不成活