暴力打表,其实可以优化

#include<iostream>
using namespace std;
int main(){
    int y,m,x;
    int a,b,c,d;
    int flag;
    int sum;
    while(cin>>y>>m>>x){
        sum=0;
        flag = 0;
        a = y%10;
        b = y/10%10;
        c = y/100%10;
        d = y/1000;
//         cout<<a<<b<<c<<d;
        if ((y % 4 == 0 && y % 100 != 0) || y % 400 == 0){
            flag = 1 ;
        }
        if(m==1 || m==3 || m==5 || m==7 || m==8 || m==10 || m==12){
            if(a==x){
                sum = sum+31;
            }
            if(b==x){
                sum = sum+31;
            }
            if(c==x){
                sum = sum+31;
            }
            if(d==x){
                sum = sum+31;
            }
            if(x==0 && m<=10){
                sum = sum + 12 + 31;
            }
            if(x==0 && m>10){
                sum = sum + 12 ;
            }
            if(x!=0){
                if(m==x && m<10){
                    sum = sum + 31;
                    if(x==1){
                        sum = sum + 2 + 10 + 1 + 1;
                    }
                    else if(x==2){
                        sum = sum + 1 + 2 + 10;
                    }
                    else if(x==3){
                        sum = sum + 1 + 1 + 2 + 1;
                    }
                    else {
                        sum = sum + 3 ;
                    }
                }
                if(m!=x && m<10){
                    if(x==1){
                        sum = sum + 2 + 10 + 1 + 1;
                    }
                    else if(x==2){
                        sum = sum + 1 + 2 + 10;
                    }
                    else if(x==3){
                        sum = sum + 1 + 1 + 2 + 1;
                    }
                    else {
                        sum = sum + 3 ;
                    }
                }
                if(m>=10 && x==1){
                    if(m==11){
                        sum = sum + 31;
                    }
                    sum = sum + 31 + 2 + 10 + 1 + 1;
                }
                if(m>=10 && x==2){
                    if(m==12){
                        sum = sum + 31 + 1 + 2 + 10;
                    }
                    else{
                        sum = sum + 1 + 2 + 10;
                    }
                }
                if(m>=10 && x==3){
                    sum = sum + 5;
                }
                if(m>=10 && x>3){
                    sum = sum + 3;
                }
            }
        }
        if(m==4 || m==6 || m==9 || m==11 ){
            if(a==x){
                sum = sum+30;
            }
            if(b==x){
                sum = sum+30;
            }
            if(c==x){
                sum = sum+30;
            }
            if(d==x){
                sum = sum+30;
            }
            if(x==0 && m<=10){
                sum = sum + 12 + 30;
            }
            if(x==0 && m>10){
                sum = sum + 12 ;
            }
            if(x!=0){
                if(m==x && m<10){
                    sum = sum + 30;
                    if(x==1){
                        sum = sum + 2 + 10 + 1 ;
                    }
                    else if(x==2){
                        sum = sum + 1 + 2 + 10;
                    }
                    else if(x==3){
                        sum = sum + 1 + 1 + 2 ;
                    }
                    else {
                        sum = sum + 3 ;
                    }
                }
                if(m!=x && m<10){
                    if(x==1){
                        sum = sum + 2 + 10 + 1 ;
                    }
                    else if(x==2){
                        sum = sum + 1 + 2 + 10;
                    }
                    else if(x==3){
                        sum = sum + 1 + 1 + 2 ;
                    }
                    else {
                        sum = sum + 3 ;
                    }
                }
                if(m>=10 && x==1){
                    if(m==11){
                        sum = sum + 30;
                    }
                    sum = sum + 30 + 2 + 10 + 1 ;
                }
                if(m>=10 && x==2){
                    if(m==12){
                        sum = sum + 31 + 1 + 2 + 10;
                    }
                    else{
                        sum = sum + 1 + 2 + 10;
                    }
                }
                if(m>=10 && x==3){
                    sum = sum + 4;
                }
                if(m>=10 && x>3){
                    sum = sum + 3;
                }
            }
        }
        if(m==2 && flag == 0){
            if(a==x){
                sum = sum+28;
            }
            if(b==x){
                sum = sum+28;
            }
            if(c==x){
                sum = sum+28;
            }
            if(d==x){
                sum = sum+28;
            }
            if(x==0 && m<=10){
                sum = sum + 11 +28;
            }
            if(x!=0){
                if(m==x){
                    sum = sum + 28 + 1 + 2 + 9;
                }
                if(x==1){
                    sum = sum + 2 + 10 + 1;
                }
                if(x==9){
                    sum = sum + 2;
                }
                if(x>2 && x<9){
                    sum = sum + 3;
                }
            }
        }
        if(m == 2 && flag == 1){
            if(a==x){
                sum = sum+29;
            }
            if(b==x){
                sum = sum+29;
            }
            if(c==x){
                sum = sum+29;
            }
            if(d==x){
                sum = sum+29;
            }
            if(x==0 && m<=10){
                sum = sum + 11 + 29;
            }
            if(x!=0){
                if(m==x){
                    sum = sum + 29 + 1 + 2 + 10;
                }
                if(x==1){
                    sum = sum + 2 + 10 + 1;
                }
                if(x>2){
                    sum = sum + 3;
                }
            }
        }
        cout<<sum<<endl;
    }
}