codeforces 271A --- beautiful year

BEAUTIFUL YEAR
It seems like the year of 2013 came only yesterday. Do you know a curious fact? The year of 2013 is the first year after the old 1987 with only distinct digits.
Now you are suggested to solve the following problem: given a year number, find the minimum year number which is strictly larger than the given one and has only distinct digits.
Input
The single line contains integer y (1000 ≤ y ≤ 9000) — the year number.
Output
Print a single integer — the minimum year number that is strictly larger than y and all it's digits are distinct. It is guaranteed that the answer exists.
Examples
input
1987
output
2013
input
2013
output
2014

  1. #include <iostream>
  2. using namespace std;
  3. int iFind ( int iIn )
  4. {
  5. int iFlag; 
  6. int iBucket[10];
  7. for ( int i=0 ; i<10 ; i++ )
  8.     iBucket[i] = 0;
  9. iFlag = 0;
  10. while ( iIn )
  11.     {
  12.     if ( iBucket[iIn%10] == 0 )
  13.         iBucket[iIn%10]++; 
  14.     else
  15.         iFlag = 1;
  16.     //cout << iIn <<endl;
  17.     iIn = iIn/10;  
  18.     }  
  19. return  iFlag;
  20. }
  21. int main()
  22. {
  23. int iYear;
  24. int iTemp;
  25. cin >> iYear;
  26. while (1)
  27.     {
  28.     //cout << iYear << " ";
  29.     iYear++;   
  30.     iTemp = iFind(iYear);
  31.     if ( iTemp == 0 )
  32.         {
  33.         cout << iYear << endl;
  34.         break; 
  35.         }          
  36.     }  
  37. }

留言

這個網誌中的熱門文章

Codeforces --- string task

Uva 674 ---- coin change