Codeforces Round #166 (Div. 2) A. Beautiful Year

http://codeforces.com/problemset/problem/271/A

题意:输入一个年份,输出之后离它最近的一个漂亮年。(4位数字均不相同)

代码:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#include <bits/stdc++.h>
using namespace std;

int main() {
int n;
cin >> n;
for (int i = n + 1; ; i++) {
bool c[10];
memset(c, 0, sizeof(c));
bool flag = true;
int ii = i;
while (ii) {
if (c[ii % 10]) { flag = false; }
// 说明这个数字出现过,标记为假
// 当然把标记标为假后可以用break判断下一年
c[ii % 10] = true;
// 当前数字出现一次,
ii /= 10;
}
if (flag) {
cout << i << endl;
return 0;
}
}
}