Advertisement
tosip

Untitled

Jun 2nd, 2021
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.85 KB | None | 0 0
  1.  
  2. #include <bits/stdc++.h>
  3.  
  4. using namespace std;
  5.  
  6. int main()
  7. {
  8.     ifstream file("input.txt");
  9.     string str;
  10.     int low, high, validPasswords = 0;
  11.     while (getline(file, str))
  12.     {
  13.         char c = str[str.find(':') - 1];
  14.         size_t found;
  15.         if ((found = str.find("-")) != string::npos)
  16.         {
  17.             low = stoi(str.substr(0, found));
  18.             high = stoi(str.substr(found + 1, string::npos));
  19.             //cout << low << " " << high << endl;
  20.  
  21.             int cnt = 0;
  22.             for (int i = 0; i <= str.size(); i++)
  23.             {
  24.                 if (str[i] == c)
  25.                 {
  26.                     cnt++;
  27.                 }
  28.             }
  29.             if ((cnt >= low) && (cnt <= high))
  30.             {
  31.                 validPasswords++;
  32.             }
  33.         }
  34.     }
  35.     cout << validPasswords << "\n";
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement