/*
简单的数组下标操作
做的时候最好在草稿纸上列举实例走流程以免思维错误
*/
/*
Run Time: 0secs
Run Memory: 312KB
*/
#include <iostream>
#include <string>
using namespace std;
int col; //2-20
int row;
string input; //1-200
int main()
{
while (cin>>col && col){
cin >> input;
row = input.length() / col;
char result[row][col];
for(int i=0; i<row; i++){
int base = col * i;
if(i%2 == 0){ //从左到右
for(int j=0; j<col; j++){
char buf = input[base + j];
result[i][j] = buf;
}
}else{
for(int j=0; j<col; j++){
char buf = input[base + (col-j-1)];
result[i][j] = buf;
}
}
}
for(int j=0; j<col; j++){
for(int i=0; i<row; i++){
cout << result[i][j];
}
}
cout << endl;
}
return 0;
}
Sicily 1007. To and Fro
最新推荐文章于 2017-02-25 21:58:16 发布