Created
March 2, 2015 17:41
-
-
Save junfenglx/e7840f9aa9faf022f56e to your computer and use it in GitHub Desktop.
This file contains hidden or 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 <vector> | |
#include <string> | |
void print(const std::string &s, size_t i) { | |
size_t len = s.length(); | |
size_t space_count = i < len ? i : len; | |
for(size_t j = 0; j < space_count; ++j) | |
std::cout << " "; | |
if (space_count < len) | |
std::cout << s.c_str() + i; | |
} | |
int main() | |
{ | |
using namespace std; | |
vector<string> words; | |
size_t max_len = 0; | |
while(true) | |
{ | |
string s; | |
cin >> s; | |
if (!cin) | |
break; | |
string t(s); | |
if (max_len < t.length()) | |
max_len = t.length(); | |
words.push_back(t); | |
} | |
for (size_t i=0; i < max_len; ++i) | |
{ | |
vector<string>::const_iterator start = words.begin(); | |
print(*start, i); | |
for(start = start + 1; start != words.end(); ++start) | |
{ | |
cout << " "; | |
print(*start, i); | |
} | |
cout << endl; | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment