---
# System prepended metadata

title: 題目

---

# 題目

## Minmizing a string

<details>
<summary>測資對，尚未測驗</summary>
 
```cpp
    // 測資對，尚未測驗
    #include <iostream>
    #include <string>
    using std::string;

    int main (void) {
        string s;
        std::cin >> s;
        std::cout << "Input: " << s << std::endl;
        const int lens = s.length();

        auto swap = [&] (const int a, const int b) -> void {
            char tmp = s[a];
            s[a] = s[b];
            s[b] = tmp;
        };
        int index = 0;
        while (index < lens) {
            while (s[index] == 'b' && s[index + 1] == 'a' && index < lens) {
                swap(index, index + 1);
                --index;
            }
            while (s[index] == 'c' && s[index + 1] == 'b' && index < lens) {
                swap(index, index + 1);
                --index;
            }
            ++index;
        }
        std::cout << s << std::endl;
        return 0;
    }
                             
```        
                                       
>[name=Solved by 陳肇廷]
    
</details> 

    
## Count of distinct integers 
<details>
<summary>測驗全對</summary>   

```cpp
int max_num(int n) {
    queue<int> board;
    unordered_set<int> ans;

    ans.insert(n);
    board.push(n);

    while (!board.empty()) {
        int x = board.front();
        board.pop();

    for (int i = 1; i <= x; ++i) {
        if (x % i == 1) {
            if (!ans.count(x - i)) {
                board.push(x - i);
                ans.insert(x - i);
            }
        }
    }

    return ans.size();
}
```
>[name=Solved by 鄭太睿宏]
    
</details>


    
## Valid BST Permutations
<details>
<summary>全錯笑死</summary>
    
```cpp 
vector<int> numBST(vector<int> nodeValues) {
    const int lens = nodeValues.size();
    int max = -1;
    vector<unsigned long int> T;
    
    for (int i = 0; i < lens; ++i) max = max > nodeValues[i] ? max : nodeValues[i];
    T.resize(max);
    T[0] = T[1] = 1;
    
    
    auto count = [&](const int n) -> void {
        for (int i = 2; i <= n; i++) {
            for (int j = 1; j <= i; j++) {
                T[i] += (T[i - j] * T[j - 1]);
            }
        }
    };
    
    count(max);
    
    vector<int> ans;
    for (int i = 0; i < lens; ++i) {
        ans.push_back(T[nodeValues[i]] % 100000007);
    }
    
    return ans;
}
```
    
</details>
    
## Characters Swap

<details>

<summary>全對</summary>
    
```cpp 
string getString(string s) {
    const int lens = s.length();
    bool has[26];
    vector<char> T;
    for (int i = 0; i < 26; ++i) has[i] = false;
    for (int i = 0; i < lens; ++i) {
        has[s[i] - 'a'] = true;
    }
    for (int i = 25; i >= 0; --i) if (has[i]) T.push_back('a' + i);
    // for (int i = 0; i < T.size(); ++i) cout << T[i] << endl;
    
    int index = 0;
    bool changed[lens];
    for (int i = 0; i < lens; ++i) changed[i] = false;
    
    for (int i = 0; i < lens; ) {
        if (!changed[i]) {
            // cout << i << ": ";
            const char tmp = s[i];
            const char curChange = T.back();
            T.pop_back();
            for (int j = 0; j < lens; ++j) {
                if(s[j] == tmp && changed[j] == false) {
                    // cout << "s[j] = " << s[j] << endl;
                    s[j] = curChange;
                    changed[j] = true;
                }
            }
            while (changed[i]) ++i;
        } else ++i;
        // cout << s << endl;
    }
    return s;
}
```
>[name=Solved by 陳肇廷]
</details>