首页 > 代码库 > [sicily online]1007. To and Fro

[sicily online]1007. To and Fro


#include<iostream> 
#include<string> 
#include<string.h> 
using namespace std; 
 
char message[20][200]; 
 
int main() 

    string msg; 
    int col; 
    while(cin>>col&&col!=0) 
    { 
        cin>>msg; 
        int line=(msg.size()+1)/col; 
        for(string ::size_type i=0;i<msg.size();i++) 
       { 
            int hang=i/col; 
            int lie; 
            hang%2==0?lie=i%col:lie=col-1-i%col; 
            message[hang][lie]=msg[i]; 
        }//end for 
 
       for(int j=0;j<col;j++) 
        { 
            for(int i=0;i<line;i++)                  cout<<message[i][j]; 
       }//end for 
        cout<<endl; 
    }//end while 

[sicily online]1007. To and Fro