tut

HỒ PHÚC NHẬT ANH  •  1 tháng trước


include <stdio.h>

int main(){

int a, b, c, d;
scanf("%d%d%d%d", &a, &b, &c, &d);
//tao 1 bien chua cac thanh phan vua nhap
int chua[4]={a, b, c, d};
//tao bien neu khong tao dc se hien thi -1
int thoigiancu = -1;
// dat -1 cho de nhan biet neu loi sai
int kqgio = -1;
int kqphut = -1;

for(int i=0; i <= 3; i++){
    for(int j=0; j<=3; j++){
        for(int k=0; k<=3; k++){
            for(int l=0; l<=3; l++){
                if(i!=j && i!=k && i!=l && j!=k && j!=l && k!=l){
                    int gio =(chua[i] *10) + chua[j];
                    int phut =(chua[k] *10) + chua[l];
                    
                    if(gio <24 && phut < 60){
                        int tongphut = (gio * 60) + phut;
                        	if(tongphut > thoigiancu){
                           		 thoigiancu = tongphut;
                           		 kqgio = gio;
                           		 kqphut = phut;
                        }
                    }
                    	
                    
                }
            }
        }
    }
}
        if(thoigiancu == -1){
            printf("%d", thoigiancu);
        }
        else
        {
            printf("%.2d:%.2d", kqgio, kqphut);
        }
        return 0;

}


Bình luận: