Day 6
This commit is contained in:
parent
b92b49fe98
commit
666fdea266
22
Day6/part1.cpp
Normal file
22
Day6/part1.cpp
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
#include <iostream>
|
||||||
|
#include <string>
|
||||||
|
#include <algorithm>
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
int main(int argc, char* argv[])
|
||||||
|
{
|
||||||
|
string signal;
|
||||||
|
cin >> signal;
|
||||||
|
|
||||||
|
for (int i = 0; i < signal.size()-4; i++)
|
||||||
|
{
|
||||||
|
string segment = signal.substr(i,4);
|
||||||
|
sort(segment.begin(), segment.end());
|
||||||
|
if (segment.end() == std::unique(segment.begin(), segment.end()))
|
||||||
|
{
|
||||||
|
cout << i+4 << endl;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
22
Day6/part2.cpp
Normal file
22
Day6/part2.cpp
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
#include <iostream>
|
||||||
|
#include <string>
|
||||||
|
#include <algorithm>
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
int main(int argc, char* argv[])
|
||||||
|
{
|
||||||
|
string signal;
|
||||||
|
cin >> signal;
|
||||||
|
|
||||||
|
for (int i = 0; i < signal.size()-14; i++)
|
||||||
|
{
|
||||||
|
string segment = signal.substr(i,14);
|
||||||
|
sort(segment.begin(), segment.end());
|
||||||
|
if (segment.end() == std::unique(segment.begin(), segment.end()))
|
||||||
|
{
|
||||||
|
cout << i+14 << endl;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user