practice_greedyTextJustific.../cpp_impl/src/main.cpp

45 lines
1.1 KiB
C++
Raw Normal View History

2021-05-10 05:32:47 +00:00
#include <iostream>
2021-05-10 06:15:33 +00:00
#include <string>
#include <vector>
2021-05-10 05:16:10 +00:00
2021-05-10 06:15:33 +00:00
#include "helpers.hpp"
2021-05-10 05:16:10 +00:00
int main(int argc, char **argv) {
2021-05-10 06:15:33 +00:00
auto parsed = Helpers::parseArgs(argc, argv, {}, {"w", "string"});
2021-05-10 05:32:47 +00:00
2021-05-10 06:15:33 +00:00
// for(auto pair : parsed) {
// std::cout << pair.first << ", " << pair.second << std::endl;
// }
unsigned long long width;
if(auto iter = parsed.find("w"); iter != parsed.end()) {
width = std::stoull(iter->second);
std::cout << "Got width == " << width << std::endl;
} else {
return 1;
}
std::string str;
if(auto iter = parsed.find("string"); iter != parsed.end()) {
str = iter->second;
std::cout << "Got string == \"" << str << "\"" << std::endl;
} else {
return 2;
2021-05-10 05:32:47 +00:00
}
2021-05-10 06:15:33 +00:00
Helpers::printDividers(width);
std::vector<std::string> tokens = Helpers::strSplit(str, {' ', '\n', '\r'});
// for(auto token : tokens) {
// std::cout << token << '\n';
// }
// std::cout << std::endl;
Helpers::printGreedyTextJustification(width, tokens);
Helpers::printDividers(width);
2021-05-10 05:16:10 +00:00
return 0;
}