标签:
Case #1: 123456789 Case #2: Hello, welcome to my dream world! Case #3: Toodming is best Case #4: sokaisan
这是一道思维题,给了我们密文,让我们倒着推回去,只需把密文挨着填到原文的各个段位上去就好了。
#include <cstdio> #include <cstring> char str[100000 + 10]; char bob[100000 + 10]; int iCase; int n; int main() { scanf("%d", &iCase); getchar(); for (int k = 1; k <= iCase; k++) { gets(str); scanf("%d", &n); getchar(); int len = strlen(str); int row = len/n + 1; int rest = len % n; int cur = 0; for (int i = 0; i < rest; i++) for (int j = 0; j < row; j++) bob[i + n*j] = str[cur++]; for (int i = rest; i < n; i++) for (int j = 0; j < row - 1; j++) bob[i + n*j] = str[cur++]; printf("Case #%d:\n", k); for (int i = 0; i < cur; i++) printf("%c", bob[i]); printf("\n"); } return 0; }
标签:
原文地址:http://blog.csdn.net/sureina/article/details/51362281