9
9
using namespace std ;
10
10
11
11
const bool DEBUG=false ;
12
+ const bool DEBUG2=false ;
12
13
13
14
bool compare (string l, string r){ // l<=r operation
14
15
if (DEBUG) cout<<" comparing " <<l<<" <= " <<r<<endl;
@@ -129,6 +130,24 @@ void part_one(ifstream& inp_file, long int& ans){
129
130
}
130
131
}
131
132
133
+ void part_two (ifstream& inp_file, long int & ans){
134
+ string s;
135
+
136
+
137
+ string first_key=" [[2]]" ;
138
+ int first_key_pos=1 ;
139
+ string second_key=" [[6]]" ;
140
+ int second_key_pos=2 ;
141
+ while (getline (inp_file, s)){
142
+ if (s.size ()==0 ) continue ;
143
+ if (DEBUG2) cout<<s<<endl;
144
+ if (!compare (first_key,s)) first_key_pos++;
145
+ if (!compare (second_key,s)) second_key_pos++;
146
+ if (DEBUG2) cout<<first_key_pos<<" * " <<second_key_pos<<endl;
147
+ }
148
+ ans=first_key_pos*second_key_pos;
149
+ }
150
+
132
151
int main (int argc,char * argv[]){
133
152
134
153
if (argc>1 ){
@@ -143,7 +162,8 @@ int main(int argc,char* argv[]){
143
162
144
163
long int ans=0 ;
145
164
146
- part_one (inp_file,ans);
165
+ // part_one(inp_file,ans);
166
+ part_two (inp_file,ans);
147
167
148
168
149
169
if (DEBUG) cout<<" \n ------------" <<endl;
0 commit comments