The Lastest Time-hihocode-tiger

描述

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.  

样例输入
0 9 0 0
样例输出

09:00

这道题打击自信,本来hiho一周一道,一遍AC,就想着做一下tiger,结果第一道题就GG了N次,

主要还是自己考虑的太少了!!!!!!以后考虑问题要全面

#include 
using namespace std;
int a[4];
int res[24];
int AnsCal( )
{int temp[24];int i = 0;sort(a, a+4);res[i] = a[0]*1000+a[1]*100+a[2]*10+a[3];while( next_permutation(a, a+4)){res[++i] = a[0]*1000+a[1]*100+a[2]*10+a[3];}int k = i, j=0;temp[0] = 9999;sort(res, res+k);for( i=0 ; i<=k ; i++ ){if( res[i]/100 <= 23 && res[i]%100 <= 59  ){temp[++j] = res[i];}}return temp[j];
}
int main()
{cin>>a[0]>>a[1]>>a[2]>>a[3];int ans = AnsCal();if( ans<= 2359 )printf("%02d:%02d\n", ans/100, ans%100);elseprintf("NOT POSSIBLE\n");//cout << "Hello world!" << endl;return 0;
}


本文来自互联网用户投稿,文章观点仅代表作者本人,不代表本站立场,不承担相关法律责任。如若转载,请注明出处。 如若内容造成侵权/违法违规/事实不符,请点击【内容举报】进行投诉反馈!

相关文章

立即
投稿

微信公众账号

微信扫一扫加关注

返回
顶部