diff options
| author | Paulo Custodio <pauloscustodio@gmail.com> | 2023-03-02 21:32:53 +0000 |
|---|---|---|
| committer | Paulo Custodio <pauloscustodio@gmail.com> | 2023-03-02 21:32:53 +0000 |
| commit | 38d82321ddc0f1b10d9c8e97ebbcbfbfa5d5a8d9 (patch) | |
| tree | 7b471f58e0e3091231d0c82cb7523dffb0a01c33 /challenge-204/paulo-custodio/cpp/ch-2.cpp | |
| parent | 5c33806bdd7d70d9179fec0594ffec63afa23ab2 (diff) | |
| download | perlweeklychallenge-club-38d82321ddc0f1b10d9c8e97ebbcbfbfa5d5a8d9.tar.gz perlweeklychallenge-club-38d82321ddc0f1b10d9c8e97ebbcbfbfa5d5a8d9.tar.bz2 perlweeklychallenge-club-38d82321ddc0f1b10d9c8e97ebbcbfbfa5d5a8d9.zip | |
whitespace
Diffstat (limited to 'challenge-204/paulo-custodio/cpp/ch-2.cpp')
| -rw-r--r-- | challenge-204/paulo-custodio/cpp/ch-2.cpp | 62 |
1 files changed, 31 insertions, 31 deletions
diff --git a/challenge-204/paulo-custodio/cpp/ch-2.cpp b/challenge-204/paulo-custodio/cpp/ch-2.cpp index 331715e1c7..0904357163 100644 --- a/challenge-204/paulo-custodio/cpp/ch-2.cpp +++ b/challenge-204/paulo-custodio/cpp/ch-2.cpp @@ -54,41 +54,41 @@ std::vector<int> data; size_t rows = 0, cols = 0; void parse_data() { - std::string line; - while (std::getline(std::cin, line)) { - if (line.find('[') != std::string::npos) { - size_t pos; - while ((pos = line.find('[')) != std::string::npos) line[pos] = ' '; - while ((pos = line.find(']')) != std::string::npos) line[pos] = ' '; - std::istringstream iss{ line }; - int n; - while (iss >> n) { - data.push_back(n); - } - } - else { - std::istringstream iss{ line }; - iss >> rows >> cols; - break; - } - } + std::string line; + while (std::getline(std::cin, line)) { + if (line.find('[') != std::string::npos) { + size_t pos; + while ((pos = line.find('[')) != std::string::npos) line[pos] = ' '; + while ((pos = line.find(']')) != std::string::npos) line[pos] = ' '; + std::istringstream iss{ line }; + int n; + while (iss >> n) { + data.push_back(n); + } + } + else { + std::istringstream iss{ line }; + iss >> rows >> cols; + break; + } + } } void output_data() { - if (data.size() != rows*cols) - std::cout << "0" << std::endl; - else { - for (int i = 0; i < rows; i++) { - std::cout << "[ "; - for (int j = 0; j < cols; j++) { - std::cout << data[i*cols+j] << " "; - } - std::cout << "]" << std::endl; - } - } + if (data.size() != rows*cols) + std::cout << "0" << std::endl; + else { + for (int i = 0; i < rows; i++) { + std::cout << "[ "; + for (int j = 0; j < cols; j++) { + std::cout << data[i*cols+j] << " "; + } + std::cout << "]" << std::endl; + } + } } int main() { - parse_data(); - output_data(); + parse_data(); + output_data(); } |
