出生年(15)

#include <stdio.h>
#include <stdlib.h>

int getNum(int age){
    int a,b,c,d;
    int num[10]={0};
    a=age%10;
    b=age/10%10;
    c=age/100%10;
    d=age/1000;
    num[a]++;
    num[b]++;
    num[c]++;
    num[d]++;
    if(num[a]==4||num[b]==4||num[c]==4||num[d]==4)
        return 1;
    if(num[a]==3||num[b]==3||num[c]==3||num[d]==3)
        return 2;
    if(num[a]==1&&num[b]==1&&num[c]==1&&num[d]==1)
        return 4;
    if(num[a]==1||num[b]==1||num[c]==1||num[d]==1)
        return 3;
    return 2;

}

int main()
{
    int age,num,i;
    scanf("%d%d",&age,&num);
    for(i=0;;i++){
        if(getNum(age+i)==num)
            break;
    }
	printf("%d %04d",i,age+i);
	return 0;
}
原文地址:https://www.cnblogs.com/pprp/p/8612728.html