弱鸡解决法:老夫写代码从来不知道什么叫算法,什么函数 就是暴力破解就完事了 直接就printf 能捞就捞
#include<stdio.h>
int main(){
int y,d;
scanf("%d%d",&y,&d);
if((y%4==0&&y%100!=0)||y%400==0){ //闰年
if(d>=1&&d<=31){
printf("1\n%d",d);
}
else if(d<=60){
printf("2\n%d",d-31);
}
else if(d<=91){
printf("3\n%d",d-60);
}
else if(d<=121){
printf("4\n%d",d-91);
}
else if(d<=152){
printf("5\n%d",d-121);
}
else if(d<=182){
printf("6\n%d",d-152);
}
else if(d<=213){
printf("7\n%d",d-182);
}
else if(d<=244){
printf("8\n%d",d-213);
}
else if(d<=274){
printf("9\n%d",d-244);
}
else if(d<=305){
printf("10\n%d",d-274);
}
else if(d<=335){
printf("11\n%d",d-305);
}
else {
printf("12\n%d",d-335);
}
}
else{ //p平年
if(d>=1&&d<=31){
printf("1\n%d",d);
}
else if(d<=59){
printf("2\n%d",d-31);
}
else if(d<=90){
printf("3\n%d",d-59);
}
else if(d<=120){
printf("4\n%d",d-90);
}
else if(d<=151){
printf("5\n%d",d-120);
}
else if(d<=181){
printf("6\n%d",d-151);
}
else if(d<=212){
printf("7\n%d",d-181);
}
else if(d<=243){
printf("8\n%d",d-212);
}
else if(d<=273){
printf("9\n%d",d-243);
}
else if(d<=304){
printf("10\n%d",d-273);
}
else if(d<=334){
printf("11\n%d",d-304);
}
else {
printf("12\n%d",d-334);
}
}
return 0;
}
续一个正统的:
#include<stdio.h>
int main(){
int y,d,month=1;
scanf("%d%d",&y,&d);
int m[12]={31,28,31,30,31,30,31,31,30,31,30,31};
if((y%4==0&&y%100!=0)||y%400==0){ //闰年
m[1]=29; //二月改为29天
for(int i=0;i<12;i++){
if(d-m[i]>0){
month++;
d-=m[i];
}
else break;
}
}
else{ //平年
for(int i=0;i<12;i++){
if(d-m[i]>0){
month++;
d-=m[i];
}
else break;
}
}
printf("%d\n%d",month,d);
return 0;
}
欢迎指导交流。