不难,代码:
#include <queue> #include <functional> #include <stdio.h> #include <string.h> #include <iostream> #include <algorithm> #include <stack> #include <vector> #include <set> #include <map> #include <string> #include <cmath> #include <cstdlib> #include <ctime> #include <assert.h> using namespace std; /*题意: 当前年份为a,求当前和未来最近的某一年,年份各位数字的不同个数等于b */ #define N 1005 inline int f(int a) { int aa = a % 10; a /=10; int bb = a % 10; a /=10; int cc = a % 10; a /= 10; int dd = a; int ans = 1; if(aa!=bb && aa != cc && aa != dd) ans++; if(bb!=cc && bb != dd) ans++; if(cc != dd) ans++; return ans; } int main() { int a,b; scanf("%d%d",&a,&b); int cot = 0; while(1){ if(f(a) == b) break; a++; cot++; } printf("%d %04d",cot,a); return 0; }