/*
 * 演算法 / Algorithm:
 *   對每個整數呼叫 to_string 取得它的十進位字串，再把每個字元減去 '0'
 *   就得到對應的 int 位數，依序 push_back 進結果 vector。
 *   For each integer, convert to a decimal string and push each
 *   (char - '0') into the answer vector — already in MSB-first order.
 */

#include <vector>      // std::vector：動態長度陣列 / dynamic array
#include <string>      // std::to_string：int → string
using namespace std;

class Solution {
public:
    vector<int> separateDigits(vector<int>& nums) {
        vector<int> ans;          // 答案容器，會自動擴容 / output, grows automatically
        ans.reserve(nums.size() * 6);  // 預留容量，減少重新配置 / pre-allocate to avoid reallocs

        // 範圍式 for 迴圈：依序取出 nums 中每個元素
        // Range-based for: visit each element of nums in order.
        for (int x : nums) {
            // to_string 把整數轉成十進位字串，例如 13 → "13"
            // to_string converts the int to its decimal text form.
            string s = to_string(x);

            // 對字串的每個字元 c，'c' - '0' 把它變回 0~9 的整數
            // For each char c, (c - '0') maps '0'..'9' to 0..9 (ASCII arithmetic).
            for (char c : s) {
                ans.push_back(c - '0');  // 追加到答案末端 / append digit
            }
        }
        return ans;   // vector 會以值回傳，內含全部位數 / returned by value
    }
};
