What is latest time you can make with 4 digits A, B, C and D?
For example if the 4 digits are 1, 0, 0, 0, you can make 4 times with them: 00:01, 00:10, 01:00, 10:00. The lastest time will be 10:00. Note a valid time is between 00:00 and 23:59.
输入
One line with 4 digits A, B, C and D, separated by a space. (0 <= A, B, C, D <= 9)
输出
Output the lastest time in the format “hh:mm”. If there is no valid time output NOT POSSIBLE.
#include<iostream> #include<algorithm> #include<string> #include<cstring> #include<cmath> #include<stack> #include<vector> #include<map> #include<set> #include<queue> #include<utility> #define ll long long #define ull_ unsigned long long
usingnamespacestd ;
int(){ int a[5] ; for ( int i = 0 ; i < 4 ; i ++ ){ cin >> a[i] ; } sort(a , a + 4 , greater<int>()) ; bool check = false ; do{ if (a[0] * 10 + a[1] <= 23 && a[2] * 10 + a[3] <= 59 ){ check = true ; break ; } }while(prev_permutation(a , a + 4)) ; if ( check ){ printf("%d%d:%d%dn" , a[0] , a[1] , a[2] , a[3]) ; }else{ printf("NOT POSSIBLEn") ; } return0 ; }
近期评论