列变位法解密
Time Limit: 2000/1000 MS (Java/Others)
Memory Limit: 65536/65536 K (Java/Others)
Problem's Link: http://bestcoder.hdu.edu.cn/contests/contest_showproblem.php?cid=584&pid=1002
Mean:
略
analyse:
水题,直接画图模拟
Time complexity: O(n)
Source code:
/* * this code is made by crazyacking * Verdict: Accepted * Submission Date: 2015-05-23-13.06 * Time: 0MS * Memory: 137KB */ #include <queue> #include <cstdio> #include <set> #include <string> #include <stack> #include <cmath> #include <climits> #include <map> #include <cstdlib> #include <iostream> #include <vector> #include <algorithm> #include <cstring> #define LL long long #define ULL unsigned long long using namespace std; const int MAXN=100010; char s[MAXN]; int cha[MAXN]; int main() { int t,Cas=1; scanf("%d",&t); getchar(); while(t--) { gets(s); int n; scanf("%d",&n); getchar(); printf("Case #%d:\n",Cas++); int len=strlen(s); int line; if(len%n==0) line=len/n; else line=len/n+1; int m=len%n; memset(cha,0,sizeof cha); int cnt=1; if(m!=0) { for(int i=m+1;i<n;++i) cha[i]=cnt++; } for(int i=0;i<line;++i) { if(len%n!=0 && i==line-1) { int sta=i; for(int j=0;j<m;++j) { printf("%c",s[sta]); sta+=line; } } else { int sta=i; for(int j=0;j<n;++j) { printf("%c",s[sta-cha[j]]); sta+=line; } } } puts(""); } return 0; } /* */