-
Notifications
You must be signed in to change notification settings - Fork 172
/
sum level K.cpp
82 lines (69 loc) · 1.19 KB
/
sum level K.cpp
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#include<bits/stdc++.h>
using namespace std;
typedef long long int LL;
#define scll(x) scanf("%lld",&x);
#define sci(x) scanf("%d",&x);
#define prll(x) printf("%lld\n",x);
#define pri(x) printf("%d\n",x);
/*
3
(0(5(6()())(-4()(9()())))(7(1()())(3()())))
*/
int main()
{
int arr[2][100]={0};
int size = 0;
int x;
string str;
cin>>x;
cin>>str;
int level=0, temp=0, commit=0, neg=0;
for(int i=0; i<str.length(); i++){
if(str[i]=='(' || str[i]==')'){
if(commit == 1){
if(neg==1){
temp=temp*-1;
neg=0;
}
arr[0][size]=level;
arr[1][size]=temp;
size++;
temp=0;
}
if(str[i]=='('){
level++;
}
else if(str[i]==')'){
level--;
}
commit=0;
}
else if(str[i]=='-'){
neg=1;
commit = 1;
}
else{
temp= temp*10 + str[i] - '0';
commit = 1;
}
}
int temp0,temp1;
for(int i=0;i<size-1;i++){
for(int j=i+1; j<size; j++){
if(arr[0][j] > arr[0][i]){
temp0=arr[0][j];
temp1=arr[1][j];
arr[0][j]=arr[0][i];
arr[1][j]=arr[1][i];
arr[0][i]=temp0;
arr[1][i]=temp1;
}
}
}
int sum = 0;
for(int i=0;i<size;i++){
if(arr[0][i]==x+1) sum+=arr[1][i];
}
cout<<sum<<endl;
return 0;
}