-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patht.c
58 lines (52 loc) · 977 Bytes
/
t.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
55
56
57
58
#include <stdio.h>
#include <math.h>
int main()
{
int a[]={8,8,2,4,5,5,1};
int i,j,k=0,l,r,water=0;
for(i=0;i<7;i++)
{
if(a[k]!=0 && a[k]!=a[k+1])
{
for(j=i+1;j<7;j++)
if(a[i]<=a[j])
break;
if(j!=7)
{
for(l=i+1;l<j;l++)
if(a[i]>a[l])
{ water+=a[i]-a[l];
printf("%d i=%d l=%d\n",water,i,l);
}
i=j-1;
}
else
{
i++;
int max=i;
for(j=i+1;j<=7;j++)
{
if(a[max]<a[j])
max=j;
}
printf("max=%d %d\n",max, i);
if(max!=0)
{
for(l=i;l<=max;l++)
if(a[l]<a[max])
{
water+=a[max]-a[l];
printf("%d l=%d max=%d\n",water,l,max);}
i=max-1;
}
}
}
else
{
k++;
}
}
printf("%d",water);
getch();
return 0;
}