标签:ber put sam frame max nis c++ find sci
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 1255 Accepted Submission(s): 564
1 #include <bits/stdc++.h> 2 using namespace std; 3 4 char tab[65] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; 5 6 int main() 7 { 8 9 //printf("%d %d %d %d\n", ‘M‘, ‘i‘, ‘k‘, ‘e‘); 10 int t, k; 11 unsigned char s[1024]; 12 int i; 13 int len; 14 unsigned char a, b, c, d; 15 unsigned char s2[1024]; 16 int cas = 0; 17 int j; 18 int tot; 19 //char 20 21 scanf("%d", &t); 22 23 while (t--) { 24 scanf("%d%s", &k, s); 25 len = strlen((const char *)s); 26 printf("Case #%d: ", ++cas); 27 28 for (j = 0; j < k; ++j) { 29 tot = 0; 30 for (i = 0; i + 2 < len; i += 3) { 31 a = s[i] >> 2; 32 b = s[i] << 6, b >>= 2, b += s[i + 1] >> 4; 33 c = s[i + 1] << 4, c >>= 2, c += s[i + 2] >> 6; 34 d = s[i + 2] << 2, d >>= 2; 35 //printf("%d %d %d %d\n", a, b, c, d); 36 //printf("%c%c%c%c", tab[a], tab[b], tab[c], tab[d]); 37 s2[tot++] = tab[a]; 38 s2[tot++] = tab[b]; 39 s2[tot++] = tab[c]; 40 s2[tot++] = tab[d]; 41 } 42 if (i == len - 1) { 43 a = s[i] >> 2; 44 b = s[i] << 6, b >>= 2; 45 //printf("%c%c==\n", tab[a], tab[b]); 46 s2[tot++] = tab[a]; 47 s2[tot++] = tab[b]; 48 s2[tot++] = ‘=‘; 49 s2[tot++] = ‘=‘; 50 } else if (i == len - 2) { 51 a = s[i] >> 2; 52 b = s[i] << 6, b >>= 2, b += s[i + 1] >> 4; 53 c = s[i + 1] << 4, c >>= 2; 54 //printf("%c%c%c=\n", tab[a], tab[b], tab[c]); 55 s2[tot++] = tab[a]; 56 s2[tot++] = tab[b]; 57 s2[tot++] = tab[c]; 58 s2[tot++] = ‘=‘; 59 } 60 s2[tot] = ‘\0‘; 61 //printf("%s\n", s2); 62 strcpy((char *)s, (const char *)s2); 63 len = tot; 64 //printf("s = %s\n", s); 65 } 66 printf("%s\n", s2); 67 } 68 69 return 0; 70 }
标签:ber put sam frame max nis c++ find sci
原文地址:http://www.cnblogs.com/bofengyu/p/6786267.html