题目链接:http://acm.zzuli.edu.cn/problem.php?id=2267

       这道题用一个全排列函数,然后加一个判断就可以过了,而且这道题也不需要考虑是否为闰年,因为当年份为闰年的时候只有一种特殊情况就是02月29号,这个可以当作09月22号,所以就可以跳过这个情况了。还有需要注意的是数组需要sort一下,因为当你输入的为98765432的时候,就直接跳出了,不会遍历23456789等等其他情况。


AC代码:

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
int a[10];
int Mon[13] = {0,31,28,31,30,31,30,31,31,30,31,30,31};
string str;
int flag;

bool Check(int Y,int M,int D){
  if(M>=1&&M<=12){
    if(D <= Mon[M] && D>=1){
      return true;
    }
  }
  return false;
}

int main()
{
  while(cin>>str){
    flag = 0;
    for(int i=0;i<8;i++){
      a[i] = str[i] - '0';
    }
    sort(a,a+8);
    while(1){
      int Year = a[0]*1000+a[1]*100+a[2]*10+a[3];
      int Month = a[4]*10+a[5];
      int Day = a[6]*10+a[7];
      if(Check(Year,Month,Day)){
        flag = 1;
        break;
      }
      if(!next_permutation(a,a+8)){
        break;
      }
    }
    if(flag)printf("yes\n");
    else printf("no\n");
  }
  return 0;
}