add: 220420-CN [cpp]
This commit is contained in:
parent
dd36e2069e
commit
9a54773fbc
|
|
@ -0,0 +1,35 @@
|
||||||
|
#include <string>
|
||||||
|
#include <algorithm>
|
||||||
|
|
||||||
|
class Solution {
|
||||||
|
public:
|
||||||
|
static int lengthLongestPath(const std::string& input) {
|
||||||
|
int max = 0;
|
||||||
|
short partLen[5001]{};
|
||||||
|
|
||||||
|
for (const char* ptr = input.c_str(); *ptr; ++ptr) {
|
||||||
|
short level = 0, len = 0, current = 0, ok = 0;
|
||||||
|
for (; *ptr && *ptr == '\t'; ++ptr)
|
||||||
|
++level;
|
||||||
|
for (; *ptr && *ptr != '\n'; ++ptr, ++len)
|
||||||
|
ok |= (*ptr == '.');
|
||||||
|
partLen[level] = len;
|
||||||
|
|
||||||
|
if (!ok)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
for (int i = level; i >= 0; --i)
|
||||||
|
current += partLen[i];
|
||||||
|
max = std::max(max, current + level);
|
||||||
|
|
||||||
|
if (!*ptr)
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return max;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
auto x = Solution::lengthLongestPath("a");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
@ -3,4 +3,4 @@ PROJECT(2204)
|
||||||
|
|
||||||
SET(CMAKE_CXX_STANDARD 23)
|
SET(CMAKE_CXX_STANDARD 23)
|
||||||
|
|
||||||
ADD_EXECUTABLE(2204 220420.cpp)
|
ADD_EXECUTABLE(2204 220420-CN.cpp)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue