https://leetcode.com/problems/reorder-log-files/html
你有一個日誌數組 logs。每條日誌都是以空格分隔的字串。
對於每條日誌,其第一個字爲字母數字標識符。而後,要麼:ios
示例:git
Input: ["a1 9 2 3 1","g1 act car","zo4 4 7","ab1 off key dog","a8 act zoo"] Output: ["g1 act car","a8 act zoo","ab1 off key dog","a1 9 2 3 1","zo4 4 7"]
提示:redis
0 <= logs.length <= 100 3 <= logs[i].length <= 100 logs[i]保證有一個標識符,標識符後面有一個字。
算法一:
採用stable_sort,三元運算符算法
當兩個串有一個數字和字符串,&&符號就把三元運算符裏的條件表達式變爲false,進入表達式2,裏面是反轉,具體反轉邏輯以下。windows
true && true 數字 & 數字 字符串比較 true && false 數字 & 非數字 !false = true false && true 非數字 & 數字 !false = true false && false 非數字 & 非數字 !false = true
一、兩個數字,比較大小
二、一個數字,一個字符串。返回true
三、一個字符串,一個數字。返回true
四、兩個字符串,返回true數組
#include "pch.h" #include <iostream> #include <string> #include <vector> #include <unordered_set> #include <algorithm> using std::vector; using std::string; using std::unordered_set; class Solution { public: vector<string> reorderLogFiles(vector<string>& logs) { // use 'stable_sort' instead of the 'sort' std::stable_sort(logs.begin(), logs.end(), [](const std::string& lhs, const std::string& rhs) { auto i = lhs.find_first_of(' '), j = rhs.find_first_of(' '); bool digiti = isdigit(lhs[i + 1]); bool digitj = isdigit(rhs[j + 1]); return (!digiti && !digitj) ? lhs.substr(i + 1) < rhs.substr(j + 1) : !digiti; }); return logs; } }; int main() { Solution solution; vector<string> A1 = { "a1 9 2 3 1","g1 act car","zo4 4 7","ab1 off key dog","a8 act zoo" }; vector<string> A2 = solution.reorderLogFiles(A1); }
sort()和stable_sort()均可以進行排序,但對於相等的值,stable_sort()不會更改原先的順序,但sort()有可能更改順序,但也有可能不改。安全
C++排序之stable_sort()的方法
https://blog.csdn.net/lycx1234/article/details/54891827服務器
few lines C++ version, 8ms
https://leetcode.com/problems/reorder-log-files/discuss/193485/few-lines-C%2B%2B-version-8ms函數
isdigit(c)
若是 c 是一個數字,則該函數返回非零值,不然返回 0。
三元運算符
// 條件表達式 ? 表達式1 : 表達式2; bool b_show = true; int state = b_show ? 0 : 1; // state = 0;
Redis未受權訪問漏洞
redis 6379
覆蓋密鑰進行登陸服務器
禁止向互聯網提供非業務必須對外端口
使用密鑰認證機制遠程登陸Linux
http://www.javashuo.com/article/p-qaxcvglf-cw.html
建立存放key的文件
漏洞場景-redis未受權訪問漏洞
MFC開發相關程序
應急響應中開發圖形化小工具
使用MFC基於對話框開發小型的工具
基於對話框_消息處理
http://www.javashuo.com/article/p-ucrhtmgi-cz.html
應急響應中提取攻擊者橫向滲透的方法
怎麼進來的,作了什麼
經過搜索.pf文件能夠確認惡意程序啓動的時間。
攻擊者橫向滲透局域網的方式
攻擊者利用的Windows命令、橫向滲透工具分析結果列表