algorithms

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

main.cpp (1197B)


      1 #include <iostream>
      2 #include <vector>
      3 #include <unordered_set>
      4 #include <unordered_map>
      5 #include <algorithm>
      6 #include <queue>
      7 
      8 #define ll long long
      9 
     10 using namespace std;
     11 
     12 // no under 18
     13 // n ppl sitting there
     14 // knows either the age or drink they're having
     15 // check means learn both
     16 
     17 // what minimal number of people should be asked to make sure no one under 18 is drinking
     18 
     19 
     20 int main() {
     21 
     22     int ppl;
     23     cin >> ppl;
     24 
     25     unordered_set<string> drinks {};
     26     drinks.insert("ABSINTH");
     27     drinks.insert("BEER");
     28     drinks.insert("BRANDY");
     29     drinks.insert("CHAMPAGNE");
     30     drinks.insert("GIN");
     31     drinks.insert("RUM");
     32     drinks.insert("SAKE");
     33     drinks.insert("TEQUILA");
     34     drinks.insert("VODKA");
     35     drinks.insert("WHISKEY");
     36     drinks.insert("WINE");
     37 
     38     ll res = 0;
     39     for(int z = 0; z < ppl; ++z) {
     40         string current;
     41         cin >> current;
     42         
     43         if(drinks.contains(current)) {
     44             res += 1;
     45             continue;
     46         }
     47         
     48         try {
     49             int age = stoi(current);
     50             if(age <  18) {
     51                 res += 1;
     52             }
     53         } catch (...) {
     54             continue;
     55         }
     56         
     57     }
     58     cout << res << endl;
     59 }