链接:https://www.nowcoder.com/acm/contest/90/G
来源:牛客网
输入描述:
第一行测试样例数T(0<T<=100)
每个测试样例第一行两个正整数n,m(0<n,m<=30)
接下来的n行是一个n*m的字符矩阵
字符矩阵之后是一串只包含‘L’(左旋)和‘R’(右旋)的字符串,长度不超过1000
每个样例间输出一个空行
输出描述:
第一行两个正整数n,m
接下来的n行是一个n*m的字符矩阵
每个样例后面输出一个空行
输入
2 2 3 +-+ |+| LLRRR 3 2 -+ +| -+ LLL
输出
3 2 -+ +| -+ 2 3 |+| +-+
备注:
左旋即逆时针旋转,右旋即顺时针旋转
-通过一次左旋或右旋会变成|
|通过一次左旋或右旋会变成-
//每次旋转肯定浪费时间,可以通过计算直接输出,向左转一次,即为向右转三次,所以全部可化为右转即可 #include <bits/stdc++.h> using namespace std; const long long INF = 1e7 + 1; char str[32][32]; int n, m; void pf(int ct){ if(ct == 0){ cout << n << " " << m << endl; for(int i = 0; i < n; i++){ for(int j = 0; j < m; j++) cout << str[i][j]; cout << endl; } cout << endl; } else if(ct == 1){ cout << m << " " << n << endl; for(int j = 0; j < m; j++){ for(int i = n - 1; i >= 0; i--){ char ch = str[i][j]; if(ch == '-'){ cout << '|'; } else if(ch == '|') cout << '-'; else cout << ch; } cout << endl; } cout << endl; } else if(ct == 2){ cout << n << " " << m << endl; for(int j = n - 1; j >= 0; j--){ for(int i = m - 1; i >= 0; i--){ char ch = str[j][i]; cout << ch; } cout << endl; } cout << endl; } else if(ct == 3){ cout << m << " " << n << endl; for(int i = m - 1; i >= 0; i--){ for(int j = 0; j < n; j++){ char ch = str[j][i]; if(ch == '-'){ cout << '|'; } else if(ch == '|') cout << '-'; else cout << ch; } cout << endl; } cout << endl; } } int main(){ std::ios::sync_with_stdio(false); int t; cin >> t; while(t--){ cin >> n >> m; for(int i = 0; i < n; i++){ for(int j = 0; j < m; j++) cin >> str[i][j]; } string ss; cin >> ss; int ct = 0, len = ss.length(); for(int i = 0; i < len; i++){ if(ss[i] == 'R'){ ct++; } else{ ct--; } } ct %= 4; if(ct < 0) ct += 4; // cout << ct << endl; pf(ct); } return 0; }