mirror of
https://github.com/szymon-jozef/advent_of_code_2025.git
synced 2026-09-07 12:10:41 +02:00
1st challange done!
This commit is contained in:
@@ -9,37 +9,72 @@ vector<vector<string>> get_input(const string &FILE_NAME) {
|
|||||||
ifstream file(FILE_NAME);
|
ifstream file(FILE_NAME);
|
||||||
|
|
||||||
vector<vector<string>> result;
|
vector<vector<string>> result;
|
||||||
vector<string> local_vec;
|
|
||||||
|
|
||||||
size_t pos = 0;
|
|
||||||
string s;
|
string s;
|
||||||
|
|
||||||
while (getline(file, s)) {
|
while (getline(file, s)) {
|
||||||
while ((pos = s.find(" ")) != string::npos) {
|
size_t pos;
|
||||||
|
size_t i = 0;
|
||||||
|
|
||||||
|
while ((pos = s.find(' ')) != string::npos) {
|
||||||
if (pos == 0) {
|
if (pos == 0) {
|
||||||
s.erase(0, 1);
|
s.erase(0, 1);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
local_vec.push_back(s.substr(0, pos));
|
string word = s.substr(0, pos);
|
||||||
s.erase(0, pos);
|
s.erase(0, pos + 1);
|
||||||
}
|
|
||||||
local_vec.push_back(s);
|
if (i >= result.size()) {
|
||||||
result.push_back(local_vec);
|
result.emplace_back();
|
||||||
local_vec.erase(local_vec.end());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
result[i].push_back(word);
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
if (!s.empty()) {
|
||||||
|
if (i >= result.size()) {
|
||||||
|
result.emplace_back();
|
||||||
|
}
|
||||||
|
result[i].push_back(s);
|
||||||
|
}
|
||||||
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
int main() {
|
long long process_operation(vector<string> &input) {
|
||||||
return 0;
|
char operation = input.back()[0];
|
||||||
const string &FILE_NAME = "example.txt";
|
input.pop_back();
|
||||||
vector<vector<string>> input = get_input(FILE_NAME);
|
long long sum;
|
||||||
|
switch (operation) {
|
||||||
|
case '+':
|
||||||
|
sum = 0;
|
||||||
|
cout << "Now we are adding numbers: ";
|
||||||
|
for (string value : input) {
|
||||||
|
cout << value << " ";
|
||||||
|
sum += stoll(value);
|
||||||
|
}
|
||||||
|
cout << endl;
|
||||||
|
break;
|
||||||
|
case '*':
|
||||||
|
sum = 1;
|
||||||
|
cout << "Now we are multiplying numbers: ";
|
||||||
|
for (string value : input) {
|
||||||
|
cout << value << " ";
|
||||||
|
sum *= stoll(value);
|
||||||
|
}
|
||||||
|
cout << endl;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
cout << "The sum is " << sum << endl;
|
||||||
|
return sum;
|
||||||
|
}
|
||||||
|
|
||||||
for (vector<string> vec : input) {
|
int main() {
|
||||||
cout << "Vec: " << endl;
|
const string FILE_NAME = "input.txt";
|
||||||
for (string s : vec) {
|
vector<vector<string>> input = get_input(FILE_NAME);
|
||||||
cout << s << endl;
|
long long sum = 0;
|
||||||
;
|
for (vector<string> group : input) {
|
||||||
}
|
sum += process_operation(group);
|
||||||
}
|
}
|
||||||
|
cout << sum;
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user