1. 程式人生 > 其它 >PAT 1031 Hello World for U

PAT 1031 Hello World for U

技術標籤:PAT

#include <cstdio>
#include <iostream>

using namespace std;

int main() {

  string str;
  cin >> str;

  int N = str.length();
  int rownum = (N + 2) / 3;
  int colnum = N + 2 - 2 * rownum;

  for (int row = 0; row < rownum; row++) {
    for (int col = 0; col < colnum; col++) {
      if (col == 0) 
      {
        cout << str.at(row);
      }
      else if (col == colnum - 1)
      {
        cout << str.at(N - row - 1) << endl;
      }
      else if (row == rownum - 1)
      {
        cout << str.at(rownum + col - 1);
      }
      else {
        cout << " ";
      }
    }
  }

  return 0;
}