Created
December 5, 2020 04:03
-
-
Save m42e/1cb25e6117fbb2754505f75376fa6683 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <vector> | |
#include <fstream> | |
#include <string> | |
#include <algorithm> | |
using namespace std; | |
int main() { | |
string line; | |
ifstream myfile("Text.txt"); | |
//byr iyr eye hgt hcl ecl pid cid | |
/*byr(Birth Year) | |
iyr(Issue Year) | |
eyr(Expiration Year) | |
hgt(Height) | |
hcl(Hair Color) | |
ecl(Eye Color) | |
pid(Passport ID) | |
cid(Country ID)*/ | |
int valid = 0; | |
int valid2 = 0; | |
if (myfile.is_open()) | |
{ | |
string passport; | |
while (getline(myfile, line)) | |
{ | |
passport += line + " "; | |
if (line == "") { | |
bool byr, iyr, eyr, hgt, hcl, ecl, pid; | |
byr = iyr = eyr = hgt = hcl = ecl = pid = false; | |
if (passport.find("byr:") != std::string::npos) { | |
byr = true; | |
} | |
if (passport.find("iyr:") != std::string::npos) { | |
iyr = true; | |
} | |
if (passport.find("eyr:") != std::string::npos) { | |
eyr = true; | |
} | |
if (passport.find("hgt:") != std::string::npos) { | |
hgt = true; | |
} | |
if (passport.find("hcl:") != std::string::npos) { | |
hcl = true; | |
} | |
if (passport.find("ecl:") != std::string::npos) { | |
ecl = true; | |
} | |
if (passport.find("pid:") != std::string::npos) { | |
pid = true; | |
} | |
if (byr == iyr == eyr == hgt == hcl == ecl == pid == true) { | |
valid++; | |
} | |
if (byr == true && iyr == true && eyr == true && hgt == true && hcl == true && ecl == true && pid == true) { | |
valid2++; | |
} | |
passport = ""; | |
} | |
} | |
} | |
cout << valid; | |
cout << valid2; | |
myfile.close(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
or with some output: