列变位法解密
Accepts: 1393
Submissions: 5460
Time Limit: 2000/1000 MS (Java/Others)
Memory Limit: 65536/65536 K (Java/Others)
解题思路: 直接模拟,可能会超时!
import java.util.Scanner;
public class Main1
{
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
int T = sc.nextInt();
for (int cas = 1; cas <= T; cas++)
{
sc.nextLine();
String str = sc.nextLine();
int mi = sc.nextInt();
char c1[][] = null;
if (str.length() % mi == 0) c1 = new char[str.length()/mi][mi];
else c1 = new char[str.length()/mi+1][mi];
if (str.length() % mi != 0)
{
for (int i = 0; i < mi-str.length()%mi; i++)
{
c1[c1.length-1][mi-1-i] = 20;
}
}
for (int i = 0, k = 0; i < c1[0].length; i++)
{
for (int j = 0; j < c1.length; j++)
{
if (c1[j][i] == 20)continue;
c1[j][i] = str.charAt(k++);
}
}
System.out.println("Case #"+cas+":");
for (int i = 0; i < c1.length; i++)
{
for (int j = 0; j < c1[i].length; j++)
{
if (c1[i][j] == 20) break;
System.out.print(c1[i][j]);
}
}
System.out.println();
}
}
}