Saturday, June 28, 2014

Codeforces Round #166 (Div. 2), problem: (A) Beautiful Year solution

Codeforces Round #166 (Div. 2), problem: (A) Beautiful Year: http://codeforces.com/problemset/problem/271/A

Codeforces Round #166 (Div. 2), problem: (A) Beautiful Year editorial: http://codeforces.com/blog/entry/6662

Codeforces Round #166 (Div. 2), problem: (A) Beautiful Year solution: http://ideone.com/sNbVJQ

#include <iostream>
#include <cstdio>
using namespace std;

int main() {
    int y, a[5]={0}, n, flag=0, i;
    scanf("%d", &y);
    n=y;
    while(1) {
        n++;
        y=n;
        i=0;
        flag=0;
        while(y>0) {
            a[i]=y%10;
            y/=10;
            i++;
        }
        for(int j=0; j<3; j++) {
            for(int k=j+1; k<4; k++) if(a[j]==a[k]) {flag=1; break;}
            if(flag==1) break;
        }
        if(flag==0) break;
    }
    for(int j=3; j>=0; j--) printf("%d", a[j]);
    return 0;
}

No comments:

Post a Comment