杭电1200 To and Fro

版权声明:ACM代码随意转载。算法描述需备注来源。谢谢合作。 https://blog.csdn.net/Sensente/article/details/89810023

杭电1200 http://acm.hdu.edu.cn/showproblem.php?pid=1200

题目大意:

矩阵字符串处理。

AC代码:

#include <iostream>
#include <cstring>
#include <algorithm>
#include <memory.h>
#include <cmath>
#include <stack>
//#define DEBUG
using namespace std;
char a[205];
char tmp[205];
int t;
int tot;
int main() {
    while (cin >> t) {
        if(t==0) return 0;
        memset(a, 0, sizeof(a));
        memset(tmp, 0, sizeof(tmp));
        //memset(b, 0, sizeof(b));
        tot = 0;
        cin >> a;
        int len = strlen(a);
        int r = len / t;
        char b[r][t];
        for (int i = 0; i < r; i++) {
            for (int j = 0; j < t; j++) {
                b[i][j] = a[i * t + j];
            }
        }
        for (int i = 0; i < r; i++) {
            if (i % 2) {
                memset(tmp, 0, sizeof(tmp));
                for (int j = 0; j < t; j++) {
                    tmp[j] = b[i][j]; //b[i][j]=b[i][]
                }
                for (int k = 0, j = t - 1; k < t, j >= 0; k++, j--) {

                    b[i][k] = tmp[j];

                }
            }
        }
        int tot = 0;
        for (int i = 0; i < t; i++) {
            for(int k=0;k<r;k++) {
                cout<<b[k][i];
            }
        }
        cout << endl;


    } return 0;
}

猜你喜欢

转载自blog.csdn.net/Sensente/article/details/89810023
今日推荐