diff options
author | InigoGutierrez <inigogf.95@gmail.com> | 2019-12-26 01:41:57 +0100 |
---|---|---|
committer | InigoGutierrez <inigogf.95@gmail.com> | 2019-12-26 01:41:57 +0100 |
commit | c8327fe5cdfc8e31b8785aa169acd4939a07d25e (patch) | |
tree | c94b2de0a3ca74381b669f1ab332f33c44829d73 /c | |
parent | 99ca39a76114417fd989f3480d94edc5ebe681a5 (diff) | |
download | AceptaElReto-c8327fe5cdfc8e31b8785aa169acd4939a07d25e.tar.gz AceptaElReto-c8327fe5cdfc8e31b8785aa169acd4939a07d25e.zip |
Resuelto 442 en c++: Camellos, serpientes y kebabs.
Diffstat (limited to 'c')
-rw-r--r-- | c/442_camellosSerpientesYKebabs.cpp | 73 |
1 files changed, 73 insertions, 0 deletions
diff --git a/c/442_camellosSerpientesYKebabs.cpp b/c/442_camellosSerpientesYKebabs.cpp new file mode 100644 index 0000000..adfd34d --- /dev/null +++ b/c/442_camellosSerpientesYKebabs.cpp @@ -0,0 +1,73 @@ +#include <iostream> +#include <vector> + +std::string input, type; +std::vector<std::string> parts; +std::string tempString; +int i; + +int isUppercase(char character) { + return character >= 'A' && character <= 'Z'; +} + +void getPartsByDelim(std::string delim) { + while (input.find(delim) != std::string::npos) { + parts.push_back(input.substr(0, input.find(delim))); + input = input.substr(input.find(delim)+1); + } + parts.push_back(input); +} + +int main() { + while (std::cin >> input && !std::cin.eof()) { + // Separar variable en componentes + parts.clear(); + // Entrada CamelCase + if (isUppercase(input[0])) { + tempString.clear(); + for (char character : input) { + if (isUppercase(character)) { + parts.push_back(tempString); + tempString.clear(); + } + tempString.push_back(tolower(character)); + } + parts.push_back(tempString); + parts.erase(parts.begin()); + } + // Entrada snake_case + else if (input.find("_") != std::string::npos) { + getPartsByDelim("_"); + } + // Entrada kebab-case + else if (input.find("-") != std::string::npos) { + getPartsByDelim("-"); + + } + else { + parts.push_back(input); + } + + // Escribir variable como se pida + std::cin >> type; + if (type == "CamelCase") { + for (std::string word : parts) { + std::cout << (char)toupper(word[0]) << word.substr(1); + } + std::cout << std::endl; + } + else if (type == "snake_case") { + for (i = 0; i < (int)parts.size()-1; i++) { + std::cout << parts[i] << "_"; + } + std::cout << parts[i] << std::endl; + } + else if (type == "kebab-case") { + for (i = 0; i < (int)parts.size()-1; i++) { + std::cout << parts[i] << "-"; + } + std::cout << parts[i] << std::endl; + + } + } +} |