import java.util.Scanner;
public class 螺旋加密 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int R = sc.nextInt();
int C = sc.nextInt();
String str = sc.nextLine();
str = str.trim();
char[][] arr =new char[R][C];
int o = R*C;
int ten = 0;
String two = "";
int n = 0;
String STR = "";
for (int i = 0; i < str.length(); i++) { //按要求处理为二进制字符串
ten = str.charAt(i);
if (str.charAt(i)==32){
ten = 0;
two = Integer.toString(ten,2);
}else {
ten = ten-64;
two = Integer.toString(ten,2);
}
n = 5-two.length();
for (int j = 0; j < n; j++) {
two = "0"+two;
}
STR = STR+""+two;
n = 0;
}
o = o-STR.length();
for (int i = 0; i < o; i++) {
STR = STR+"0";
}
//System.out.println(STR);
int z = 0; //左
int y = C-1; //右
int s = 0; //下
int x = R-1; //上
int i = 1;
int a = 0;
for (int j = 0; j < STR.length(); j++) { //将该字符串按回型录入二维数组
if (i%4==1&&z<=y){
for (int k = z; k <= y; k++) {
arr[s][k] = STR.charAt(a);
a++;
}
s++;
i++;
}else if (i%4==2&&s<=x){
for (int k = s; k <= x; k++) {
arr[k][y] = STR.charAt(a);
a++;
}
y--;
i++;
}else if (i%4==3&&y>=z){
for (int k = y; k >= z; k--) {
arr[x][k] = STR.charAt(a);
a++;
}
x--;
i++;
}else if (i%4==0&&x>=s){
for (int k = x; k >= s; k--) {
arr[k][z] = STR.charAt(a);
a++;
}
z++;
i++;
}
}
for (int j = 0; j < R; j++) {
for (int k = 0; k < C; k++) {
System.out.print(arr[j][k]);
}
}
}
}
0.0分
1 人评分
C语言程序设计教程(第三版)课后习题6.7 (C语言代码)浏览:778 |
C语言程序设计教程(第三版)课后习题11.3 (C语言代码)浏览:1071 |
P1001 (C语言代码)浏览:836 |
C语言程序设计教程(第三版)课后习题7.1 (C语言代码)浏览:1267 |
C语言程序设计教程(第三版)课后习题7.4 (C语言代码)浏览:1314 |
2004年秋浙江省计算机等级考试二级C 编程题(1) (C语言代码)浏览:539 |
C语言程序设计教程(第三版)课后习题8.7 (C语言代码)浏览:609 |
C语言程序设计教程(第三版)课后习题8.8 (C语言代码)浏览:583 |
愚蠢的摄影师 (C++代码)浏览:980 |
1048题解(读入回车问题)浏览:628 |