Created
July 23, 2017 01:15
-
-
Save Staticity/ac9b130cddec5ac0ed7e10cd7e1f77c2 to your computer and use it in GitHub Desktop.
A silly, yet convenient, way to print data in competitive programming.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <string> | |
#include <vector> | |
int main() | |
{ | |
// Some random data to play with. | |
const std::vector<std::string> a = {"This", "is", "sort", "of", "silly"}; | |
// We wish to print the data separated by spaces, but only print | |
// a new line once we're at the final element. The output | |
// should be the following: | |
// | |
// "This is sort of silly\n" | |
// | |
// The index into the string " \n" is what makes this trick work. | |
for (size_t i = 0; i < a.size(); ++i) | |
{ | |
std::cout << a[i] << " \n"[i == a.size() - 1]; | |
} | |
std::cout << "This statement should be on its own line" << std::endl; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment