Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- int main()
- {
- ifstream file("input.txt");
- string str;
- int low, high, validPasswords = 0;
- while (getline(file, str))
- {
- char c = str[str.find(':') - 1];
- size_t found;
- if ((found = str.find("-")) != string::npos)
- {
- low = stoi(str.substr(0, found));
- high = stoi(str.substr(found + 1, string::npos));
- //cout << low << " " << high << endl;
- int cnt = 0;
- for (int i = 0; i <= str.size(); i++)
- {
- if (str[i] == c)
- {
- cnt++;
- }
- }
- if ((cnt >= low) && (cnt <= high))
- {
- validPasswords++;
- }
- }
- }
- cout << validPasswords << "\n";
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement