Add .clang-format and apply it
This commit is contained in:
@@ -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";
|
||||
|
Reference in New Issue
Block a user