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命令、横向渗透工具分析结果列表