fork download
  1. #include <iostream>
  2. #include <vector>
  3. #include <string>
  4.  
  5. using namespace std;
  6.  
  7. int main() {
  8. int N, M;
  9. cin >> N >> M; // Taking input for N and M
  10.  
  11. vector<string> input(N);
  12. // Taking input for N strings
  13. for (int i = 0; i < N; ++i) {
  14. cin >> input[i];
  15. }
  16.  
  17. // Generate combinations in order
  18. for (int i = 0; i < M; ++i) { // For each position (K)
  19. for (int j = 0; j < N; ++j) { // For each input string
  20. cout << input[j][i]; // Output the character at position 'i' from input string 'j'
  21. }
  22. cout << " ";
  23. }
  24.  
  25. return 0;
  26. }
  27.  
Success #stdin #stdout 0.01s 5304KB
stdin
2 3
abc 
def
stdout
ad be cf