Last active
December 8, 2017 06:31
-
-
Save bricakeld/5d56ca9ffcb86544fb07fe769384b296 to your computer and use it in GitHub Desktop.
Decimal Sequences
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Asia-Tsukuba 2015 Regionals | |
#include <iostream> | |
#include <cstring> | |
#include <cmath> | |
using namespace std; | |
int main() { | |
int n, temp, i, smallest, tempj; | |
int board[1000]; | |
bool present[10000]; | |
bool solved; | |
while (cin >> n) { | |
solved = false; | |
memset(present, false, sizeof present); | |
for (i = 0; i < n; i++) { | |
cin >> temp; | |
board[i] = temp; | |
} | |
// i here is num digits of the smallest integer | |
for (i = 0; i < n; i++) { | |
if (solved) break; | |
for (int j = 0; j < n - i; j++) { | |
temp = 0; | |
tempj = j; | |
for (int k = i; k >= 0; k--) { | |
temp += board[tempj++] * pow(10, k); | |
} | |
present[temp] = true; | |
} | |
for (int j = pow(10, i) - 1; j < pow(10, i + 1); j++) { | |
if (!present[j]) { | |
solved = true; | |
smallest = j; | |
break; | |
} | |
} | |
} | |
cout << smallest << endl; | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment