{"id":306,"date":"2024-08-19T19:14:28","date_gmt":"2024-08-19T11:14:28","guid":{"rendered":"https:\/\/wangqianming.top\/?p=306"},"modified":"2024-08-19T21:49:34","modified_gmt":"2024-08-19T13:49:34","slug":"%e4%b8%80%e4%ba%9b%e4%bb%a3%e7%a0%81%e8%ae%b0%e5%bd%95","status":"publish","type":"post","link":"https:\/\/wangqianming.top\/index.php\/2024\/08\/19\/%e4%b8%80%e4%ba%9b%e4%bb%a3%e7%a0%81%e8%ae%b0%e5%bd%95\/","title":{"rendered":"\u4e00\u4e9b\u4ee3\u7801\u8bb0\u5f55"},"content":{"rendered":"<h1>\u4e00\u4e9b\u4ee3\u7801\u8bb0\u5f55<\/h1>\n<pre><code class=\"language-c\">#include &lt;iostream&gt;\n#include &lt;sys\/types.h&gt;\n#include &lt;vector&gt;\n#include &lt;algorithm&gt;\nusing namespace std;\n\nint main() {\n    int n;\n    cin &gt;&gt; n;\n    vector&lt;string&gt; strs(n);\n    for(int i=0;i&lt;n;i++){\n        cin &gt;&gt; strs[i];\n    }\n    sort(strs.begin(), strs.end());\n    for(int i=0;i&lt;n;i++){\n        cout &lt;&lt; strs[i] &lt;&lt; &quot; &quot;;\n    }\n    cout &lt;&lt; endl;\n}<\/code><\/pre>\n<pre><code class=\"language-c\">#include &lt;iostream&gt;\n#include &lt;vector&gt;\n#include &lt;algorithm&gt;\n#include &lt;sstream&gt;\nusing namespace std;\n\nvector&lt;string&gt; split(const string&amp; s, char delimiter) {\n    vector&lt;string&gt; tokens;\n    string token;\n    stringstream ss(s);\n\n    while (getline(ss, token, delimiter)) {\n        tokens.push_back(token);\n    }\n\n    return tokens;\n}\n\nint main() {\n    vector&lt;string&gt; strs;\n    string temp;\n    while (cin &gt;&gt; temp) {\n        strs = split(temp,&#039;,&#039;);\n        sort(strs.begin(),strs.end());\n        for(int i=0;i&lt;strs.size();i++){\n            cout &lt;&lt; strs[i];\n            if(i!=strs.size()-1){\n                cout &lt;&lt; &quot;,&quot;;\n            }\n        }\n        cout &lt;&lt; endl;\n        strs.clear();\n    }\n}<\/code><\/pre>\n<pre><code class=\"language-c\">\/**\n * Definition for a binary tree node.\n * struct TreeNode {\n *     int val;\n *     TreeNode *left;\n *     TreeNode *right;\n *     TreeNode() : val(0), left(nullptr), right(nullptr) {}\n *     TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n *     TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}\n * };\n *\/\nclass Solution {\npublic:\n    vector&lt;int&gt; rightSideView(TreeNode* root) {\n        unordered_map&lt;int, int&gt; rightmostValueAtDepth;\n        int max_depth = -1;\n\n        stack&lt;pair&lt;TreeNode*,int&gt;&gt; nodeStack;\n        nodeStack.push({root,0});\n\n        while (!nodeStack.empty()) {\n            TreeNode* node = nodeStack.top().first;\n            int depth = nodeStack.top().second;\n            nodeStack.pop();\n\n            if (node != NULL) {\n                \/\/ \u7ef4\u62a4\u4e8c\u53c9\u6811\u7684\u6700\u5927\u6df1\u5ea6\n                max_depth = max(max_depth, depth);\n\n                \/\/ \u5982\u679c\u4e0d\u5b58\u5728\u5bf9\u5e94\u6df1\u5ea6\u7684\u8282\u70b9\u6211\u4eec\u624d\u63d2\u5165\n                if (rightmostValueAtDepth.find(depth) == rightmostValueAtDepth.end()) {\n                    rightmostValueAtDepth[depth] =  node -&gt; val;\n                }\n\n                nodeStack.push({node -&gt; left,depth+1});\n                nodeStack.push({node -&gt; right,depth+1});\n            }\n        }\n\n        vector&lt;int&gt; rightView;\n        for (int depth = 0; depth &lt;= max_depth; ++depth) {\n            rightView.push_back(rightmostValueAtDepth[depth]);\n        }\n\n        return rightView;\n    }\n};<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u4e00\u4e9b\u4ee3\u7801\u8bb0\u5f55 #include &lt;iostream&gt; #include &lt;sys\/types.h&gt; #in &#8230;<\/p>","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[11],"class_list":["post-306","post","type-post","status-publish","format-standard","hentry","category-uncategorized","tag-c"],"_links":{"self":[{"href":"https:\/\/wangqianming.top\/index.php\/wp-json\/wp\/v2\/posts\/306","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/wangqianming.top\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/wangqianming.top\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/wangqianming.top\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/wangqianming.top\/index.php\/wp-json\/wp\/v2\/comments?post=306"}],"version-history":[{"count":3,"href":"https:\/\/wangqianming.top\/index.php\/wp-json\/wp\/v2\/posts\/306\/revisions"}],"predecessor-version":[{"id":311,"href":"https:\/\/wangqianming.top\/index.php\/wp-json\/wp\/v2\/posts\/306\/revisions\/311"}],"wp:attachment":[{"href":"https:\/\/wangqianming.top\/index.php\/wp-json\/wp\/v2\/media?parent=306"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/wangqianming.top\/index.php\/wp-json\/wp\/v2\/categories?post=306"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/wangqianming.top\/index.php\/wp-json\/wp\/v2\/tags?post=306"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}