题目1 : The Lastest Time

时间限制:10000ms
单点时限:1000ms
内存限制:256MB

描述

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.  

<dl class="des"> <dt> 样例输入 </dt> <dd>
0 9 0 0
</dd> <dt> 样例输出 </dt> <dd>
09:00
</dd> </dl>

这应该是我做过最简单的hiho一下了。。

// Asimple
#include <bits/stdc++.h>
#define debug(a) cout<<#a<<" = "<<a<<endl
#define sysp system("pause")
using namespace std;
typedef long long ll;
const int maxn = 1000 + 5;
const int INF = 1e9+5;
ll T, n, sum, num, m, t, len, k;
int a[4];

bool check(int hh, int mm, int th, int tm) {
    if( hh<th ) return true;
    else if( hh == th ) {
        return mm<tm;
    }
    return false;
}

void input() {
   for(int i=0; i<4; i++) scanf("%d", &a[i]);
   int hh = -1, mm = -1;
   sort(a, a+4);
   do{
       int th = a[0]*10+a[1], tm = a[2]*10+a[3];
       if( th<24 && tm<60 ) {
           if( check(hh, mm, th, tm) ) {
               hh = th;
               mm = tm;
           }
       }
   }while( next_permutation(a, a+4));
   if( hh == -1 && mm == -1 ) puts("NOT POSSIBLE");
   else printf("%02d:%02d\n", hh, mm);
   // sysp;
}
 
int main() {
    input();
    return 0;
}