Problem 3: Veci
https://open.kattis.com/problems/veci
Last updated
https://open.kattis.com/problems/veci
Last updated
A couple approaches:
Brute Force: because the input is at most 6 digits, you only need to check numbers between the input and . You can check all numbers s.t. . If any have the same digits as (can be checked by counting the # of each digit), output the smallest such . Otherwise, output .
C++ has a next_permutation()
function which finds the smallest permutation larger than a given input. This function returns true
if successful, and false
if there are no more valid permutations. Example usage:
string s = "27711";
next_permutation(s.begin(), s.end()); // s is now 71127