Add .clang-format and apply it

This commit is contained in:
2021-12-02 07:18:16 +00:00
parent e58dede1b6
commit cd5e2538df
103 changed files with 2714 additions and 2132 deletions

View File

@@ -5,7 +5,8 @@
// Merge two strings of answers, preserving order and ensuring uniqueness of
// each answer.
std::string merge_answers(std::string const &a, std::string const &b) {
std::string merge_answers(std::string const& a, std::string const& b)
{
std::string result;
std::string::size_type pos_a = 0;
std::string::size_type pos_b = 0;
@@ -13,10 +14,12 @@ std::string merge_answers(std::string const &a, std::string const &b) {
if (a[pos_a] < b[pos_b]) {
result += a[pos_a];
++pos_a;
} else if (b[pos_b] < a[pos_a]) {
}
else if (b[pos_b] < a[pos_a]) {
result += b[pos_b];
++pos_b;
} else {
}
else {
assert(a[pos_a] == b[pos_b]);
result += a[pos_a];
++pos_a;
@@ -29,23 +32,22 @@ std::string merge_answers(std::string const &a, std::string const &b) {
return result;
}
int main(int argc, char **argv) {
int main(int argc, char** argv)
{
std::string current_answers;
unsigned count = 0;
for (std::string line; std::getline(std::cin, line);) {
if (!line.empty()) {
std::sort(line.begin(), line.end());
current_answers = merge_answers(current_answers, line);
} else {
std::cout << "Length of " << current_answers << " = "
<< current_answers.length() << "\n";
}
else {
std::cout << "Length of " << current_answers << " = " << current_answers.length() << "\n";
count += current_answers.length();
current_answers.clear();
}
}
std::cout << "Length of " << current_answers << " = "
<< current_answers.length() << "\n";
std::cout << "Length of " << current_answers << " = " << current_answers.length() << "\n";
count += current_answers.length();
std::cout << "Total length = " << count << "\n";