LCOV - code coverage report
Current view: top level - 03 - b.cpp (source / functions) Coverage Total Hit
Test: lcov.info Lines: 100.0 % 19 19
Test Date: 2025-10-12 18:20:59 Functions: 100.0 % 1 1
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 100.0 % 18 18

             Branch data     Line data    Source code
       1                 :             : #include <iostream>
       2                 :             : #include <fstream>
       3                 :             : #include <regex>
       4                 :             : #include <string>
       5                 :             : #include <iterator>
       6                 :             : #include <cstdint>
       7                 :             : using namespace std;
       8                 :             : 
       9                 :           2 : int main() {
      10                 :           2 :   ifstream file("input.txt");
      11         [ +  + ]:           2 :   if (!file) {
      12                 :           1 :     cerr << "Error: Could not open input file.\n";
      13                 :           1 :     return 1;
      14                 :             :   }
      15                 :           1 :   string content((istreambuf_iterator<char>(file)), {});
      16                 :           1 :   const regex r(R"(do\(\)|don't\(\)|mul\((\d{1,3}),(\d{1,3})\))");
      17                 :           1 :   uint64_t sum = 0;
      18                 :           1 :   bool enable = true;
      19                 :             : 
      20         [ +  + ]:         812 :   for (sregex_iterator it(content.begin(), content.end(), r), end; it != end; ++it) {
      21         [ +  + ]:         811 :     if (const string command = (*it).str(); command == "do()") {
      22                 :          38 :       enable = true;
      23         [ +  + ]:         773 :     } else if (command == "don't()") {
      24                 :          36 :       enable = false;
      25                 :         811 :     }
      26   [ +  +  +  +  :         811 :     sum += enable && (*it)[1].matched ? stoi((*it)[1]) * stoi((*it)[2]) : 0;
             +  +  +  + ]
      27                 :           1 :   }
      28                 :             : 
      29                 :           1 :   cout << sum;
      30         [ +  + ]:           3 : }
        

Generated by: LCOV version 2.0-1