这是在百度之星看到的。
Case #1: 123456789 Case #2: Hello, welcome to my dream world! Case #3: Toodming is best Case #4: sokaisan
第一眼的感觉就是。。。水题!事实证明的确是的!
简单的模拟,就不解释了!直接上代码!
//列变位法解密
#include <iostream>
#include <string.h>
#include <stdio.h>
using namespace std;
const int MAX = 10000005 ;
char str[MAX], ans[MAX];
int main()
{
int T, k, n, s;
scanf("%d",&T);
getchar();
for(k=1; k<=T; k++)
{
gets(str);
scanf("%d",&n);
getchar();
int len = strlen(str);
int x = len/n+1;
int y = len % n;
int cnt = 0;
for(int i = 0; i < y; i++)
{
for(int j = 0; j < x; j++)
{
ans[i+n*j] = str[cnt++];
}
}
for(int i = y; i < n; i++)
{
for(int j = 0 ; j < x - 1; j++)
{
ans[i+n*j] = str[cnt++];
}
}
printf("Case #%d:
",k);
for(int i=0; i<cnt; i++)
printf("%c",ans[i]);
printf("
");
}
return 0;
}