-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathp388.c
54 lines (54 loc) · 1.32 KB
/
p388.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
int lengthLongestPath(char* input) {
if (!input || !input[0]) return 0;
unsigned i = 0, j, k, l, depth, result = 0;
while (input[i])
{
j = i;
while (input[j] == '\t')
{
j++;
}
depth = j-i;
bool isfile = false;
k = j+1;
while (input[k] != '\n' && input[k] != '\0')
{
if (input[k] == '.')
{
isfile = true;
}
k++;
}
i = k;
if (input[i] == '\n')
{
i++;
}
if (!isfile)
{
l = k-j+1;
if (depth)
{
l += (((unsigned)(unsigned char)input[(depth-1)<<1])<<8)+(unsigned)(unsigned char)input[((depth-1)<<1)+1];
}
input[depth<<1] = (unsigned char)(l>>8);
input[(depth<<1)+1] = (unsigned char)l;
}
else
{
if (depth)
{
l = (((unsigned)(unsigned char)input[(depth-1)<<1])<<8)+(unsigned)(unsigned char)input[((depth-1)<<1)+1]+k-j;
}
else
{
l = k-j;
}
if (l > result)
{
result = l;
}
}
}
return result;
}