标签:
1 /*
2 字符串处理:要求解码,然而二维数组开不下,可以直接输出
3 只要在余数的地方判断一下就行了,vector的效率不高
4 */
5 #include <cstdio>
6 #include <iostream>
7 #include <algorithm>
8 #include <cstring>
9 #include <string>
10 #include <cmath>
11 using namespace std;
12
13 const int MAXM = 1e6 + 10;
14 const int INF = 0x3f3f3f3f;
15 char s[MAXM];
16 char ans[MAXM];
17
18 int main(void) //百度之星资格赛 1002 列变位法解密
19 {
20 int n, m, k, cas = 0;
21 int T;
22 scanf ("%d", &T); getchar ();
23 while (T--)
24 {
25 gets (s);
26 scanf ("%d", &m);
27 int len = strlen (s);
28 n = len / m;
29 k = len % m;
30
31 printf ("Case #%d:\n", ++cas);
32 int i = 0, j, l = 0, cnt;
33 while (i < len)
34 {
35 j = i; cnt = 0;
36 while (j < len)
37 {
38 printf ("%c", s[j]); ++l;
39 if (cnt < k) {j += (n + 1); ++cnt;}
40 else j += n;
41 if (l == len) break;
42 }
43 ++i; if (l == len) break;
44 }
45
46 puts (""); getchar ();
47 }
48
49 return 0;
50 }
51
52
53 /*
54 4
55 159263748
56 4
57 Hw doeetrrlloellc adoomm!,my e w
58 7
59 Toodming is best
60 16
61 sokaisan
62 1
63 */
1 /* 2 800多MS 3 */ 4 #include <cstdio> 5 #include <iostream> 6 #include <algorithm> 7 #include <cstring> 8 #include <string> 9 #include <cmath> 10 #include <vector> 11 using namespace std; 12 13 const int MAXM = 1e5 + 10; 14 const int INF = 0x3f3f3f3f; 15 char s[MAXM]; 16 vector<char> ss[MAXM]; 17 18 int main(void) //百度之星资格赛 1002 列变位法解密 19 { 20 int n, m, k, cas = 0; 21 int T; 22 scanf ("%d", &T); getchar (); 23 while (T--) 24 { 25 gets (s); 26 //getline (cin, s); 27 scanf ("%d", &m); 28 int len = strlen (s); 29 n = len / m; 30 k = len % m; 31 32 for (int i=0; i<=len; ++i) ss[i].clear (); 33 34 int l = 0; int t = k; 35 for (int j=0; j<m; ++j) 36 { 37 for (int i=0; i<n; ++i) 38 { 39 ss[i].push_back (s[l++]); 40 //ans[i][j] = s[l++]; 41 } 42 if (t > 0) ss[n].push_back (s[l++]); 43 t--; 44 } 45 46 printf ("Case #%d:\n", ++cas); 47 for (int i=0; i<n; ++i) 48 { 49 for (int j=0; j<m; ++j) 50 { 51 cout << ss[i][j]; 52 //printf ("%c", ans[i][j]); 53 } 54 } 55 for (int i=0; i<k; ++i) 56 cout << ss[n][i]; 57 //printf ("%c", ans[n][i]); 58 puts (""); getchar (); 59 } 60 61 return 0; 62 } 63 64 65 /* 66 4 67 159263748 68 4 69 Hw doeetrrlloellc adoomm!,my e w 70 7 71 Toodming is best 72 16 73 sokaisan 74 1 75 */
标签:
原文地址:http://www.cnblogs.com/Running-Time/p/4528503.html