-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
96 lines (74 loc) · 1.49 KB
/
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#ifdef __linux__
#include <string.h>
#include <stdint.h>
#elif _WIN32
#else
#error "OS not supported!"
#endif
#include <iostream>
#include <vector>
#include <fstream>
using namespace std;
int solve_1(string input){
vector<char> acc;
char c2 = 0;
for(auto chr: input){
if(c2 == 0 && acc.size() == 0)
{
c2 = chr;
continue;
}
if(c2 == 0){
if(acc.size() > 0)
c2 = acc.back();
}
if(tolower(chr) == tolower(c2) && chr != c2 ){
c2 = 0;
if(acc.size() > 0)
acc.pop_back();
continue;
}
if(acc.size() == 0){
acc.push_back(c2);
acc.push_back(chr);
}else
acc.push_back(chr);
c2 = chr;
}
return acc.size();
}
int solve_2(string input){
string buffer;
int hasz[200];
// rudimentary hashmap.
memset(hasz, 0, 200);
int minima = INT32_MAX;
for(auto _alfa: input){
int cnt =0;
char alfa = tolower(_alfa);
char code = alfa - '0';
if(hasz[code] == 1){
continue;
}
for(auto c : input){
if(alfa != tolower(c)){
buffer+= c;
}
}
int r = solve_1(buffer);
minima = (minima < r)? minima:r;
hasz[code] = 1;
buffer.clear();
}
return minima;
}
int main(){
ofstream myfile;
string input = "dabAcCaCBAcCcaDA";
string input2;
std::ifstream infile("test.txt");
std::getline(infile, input2);
cout << "solution 1: " << solve_1(input2) << endl;
cout << "solution 2: " << solve_2(input2) << endl;
return 0;
}