Iamtui1010

barsrule.cpp

Mar 12th, 2022
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.02 KB | None | 0 0
  1.     #include<iostream>
  2. #include<vector>
  3. #include<algorithm>
  4. #include<cctype>
  5. #include<cmath>
  6.  
  7. #define long long long
  8.  
  9. using namespace std;
  10.  
  11. string ban =  "ABSINTH BEER BRANDY CHAMPAGNE GIN RUM SAKE TEQUILA VODKA WHISKEY WINE";
  12.  
  13. void upcase(string &str)
  14. {
  15.     for (char &i : str)
  16.         i = toupper(i);
  17. }
  18.  
  19. bool numerical(string str)
  20. {
  21.     for (const auto &i : str)
  22.         if (i >= '0' && i <= '9')
  23.             return 1;
  24.     return 0;
  25. }
  26.  
  27. long str2num(string str)
  28. {
  29.     long res = 0;
  30.     while (str.size()){
  31.         res += (str[0]-'0')*pow(10, str.size()-1);
  32.         str.erase(0, 1);
  33.     }
  34.     return res;
  35. }
  36.  
  37. int main()
  38. {
  39.     cin.tie(0)->sync_with_stdio(0);
  40.     cout.tie(0)->sync_with_stdio(0);
  41.     //freopen("barsrule.inp", "r", stdin);
  42.     long n;
  43.     cin >> n;
  44.     //cin.ignore();
  45.     long ans = 0;
  46.     while (n--){
  47.         string s;
  48.         //getline(cin, s, '\n');
  49.         cin >> s;
  50.         upcase(s);
  51.         if (numerical(s)){
  52.             long tpr = str2num(s);
  53.             if (tpr < 18 && tpr != 16)
  54.                 ++ans;
  55.         }
  56.         else{
  57.             if ((long)ban.find(s) != -1)
  58.                 ++ans;
  59.         }
  60.     }
  61.     cout << ans << '\n';
  62.     return 0;
  63. }
Advertisement
Add Comment
Please, Sign In to add comment