// 2023 IUSB Programming Competition // Round 1 Problem 6 // Alphabetical Order // Solution by Liguo Yu #include using namespace std; int longestOrder(char * array, int n); int main() { char * letters = new char[10]; for(int i = 0; i < 10; i++) { cin >> letters[i]; } int longest = longestOrder(letters, 10); cout << 10-longest; return 0; } int longestOrder(char * array, int n) { int * list = new int[n]; // store the longest increasing oder starting from evey index for (int i = 0; i < n; i++) { list[i] = 1; // initialize to 1 } for (int i = 1; i < n; i++) { for (int j = 0; j < i; j++) { // update longest increasing order from position j by comparing its value with // values ahead of it and their longest increasing order if (array[i] > array[j] && list[i] < list[j] + 1) { list[i] = list[j] + 1; } } } int max = 1; // find the the longest longest increasing oder starting from all indecies for (int i = 0; i < n; i++) { if (max < list[i]) max = list[i]; } return max; }