algorithms

Algorithm implementations
git clone git://git.laack.co/algorithms.git
Log | Files | Refs | README

main.cpp (1270B)


      1 #include <vector>
      2 #include <unordered_map>
      3 #include <iostream>
      4 
      5 int main() {
      6 
      7     int eleCount;
      8     std::cin >> eleCount;    
      9     std::vector<int> eles {};
     10 
     11     for(int i = 0; i < eleCount; ++i) {
     12         int current;
     13         std::cin >> current;
     14         eles.push_back(current);
     15     }
     16 
     17     std::unordered_map<int,int> subsequences {};
     18 
     19     std::unordered_map<int,int> nextMapping {};
     20 
     21     int first = 4;
     22 
     23     nextMapping[first] = 8;
     24     nextMapping[8] = 15;
     25     nextMapping[15] = 16;
     26     nextMapping[16] = 23;
     27     nextMapping[23] = 42;
     28     nextMapping[42] = -1;
     29     
     30     int missed = 0;
     31 
     32     for(int i = 0; i < eleCount; ++i) {
     33 
     34         int current = eles[i];
     35 
     36         if(first == current) {
     37             subsequences[nextMapping[current]] += 1;
     38             continue;
     39         }
     40         
     41         if(subsequences[current] == 0) {
     42             missed += 1;
     43             continue;
     44         }
     45         
     46         subsequences[current] -= 1;
     47         subsequences[nextMapping[current]] += 1;
     48     }
     49 
     50     int inProgress = 0;
     51 
     52     inProgress += subsequences[8] * 1;
     53     inProgress += subsequences[15] * 2;
     54     inProgress += subsequences[16] * 3;
     55     inProgress += subsequences[23] * 4;
     56     inProgress += subsequences[42] * 5;
     57 
     58     std::cout <<  missed + inProgress << std::endl;
     59     
     60 }