1007 sicily To and Fro

#include <stdlib.h>

#include <iostream>

#include <string>

using namespace std;

#define N 100

char a[100][100];

int main()

{

    int n;

    string s;

    int h;

    while(cin>>n&&n!=0)

    {

        cin>>s;

        int size=s.length();

        h=size/n;

        for(int i=0;i<h;i++)

        {

            if(i%2==0)

            {

                for(int j=0;j<n;j++)

                {

                    a[i][j]=s[i*n+j];

                    //cout<<a[i][j]<<"***";

                }

                //cout<<endl;

            }

            else

            {

                for(int j=0;j<n;j++)

                {

                    a[i][j]=s[(i+1)*n-j-1];

                    //cout<<a[i][j]<<"---";

                }

                //cout<<endl;

            }

        }

        for(int i=0;i<n;i++)

        {

            for(int j=0;j<h;j++)

            {

                cout<<a[j][i];

            }

        }

        cout<<endl;

    }

    //system("pause");

    return 0;

}

 

你可能感兴趣的:(CI)