Day 3
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <algorithm>
|
||||
|
||||
using namespace std;
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
int total = 0;
|
||||
|
||||
string line1,line2,line3;
|
||||
while(getline(cin, line1))
|
||||
{
|
||||
getline(cin, line2);
|
||||
getline(cin, line3);
|
||||
|
||||
sort(line1.begin(), line1.end());
|
||||
sort(line2.begin(), line2.end());
|
||||
sort(line3.begin(), line3.end());
|
||||
|
||||
string first_intersection, second_intersection;
|
||||
set_intersection(line1.begin(), line1.end(), line2.begin(), line2.end(), back_inserter(first_intersection));
|
||||
set_intersection(first_intersection.begin(), first_intersection.end(), line3.begin(), line3.end(), back_inserter(second_intersection));
|
||||
|
||||
int value;
|
||||
if (second_intersection[0] >= 'a')
|
||||
{
|
||||
value = second_intersection[0]-'a'+1;
|
||||
}
|
||||
else
|
||||
{
|
||||
value = second_intersection[0]-'A'+27;
|
||||
}
|
||||
|
||||
total += value;
|
||||
}
|
||||
cout << total << endl;
|
||||
}
|
||||
Reference in New Issue
Block a user