标签:
#include<cstdio> #include<cstring> #include<algorithm> using namespace std; int T,k; char s[1100]; char s3[1100]; char s2[50]; int a[110]; char s1[100] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; int n,x,y; int flag,num; void base() { flag = 1; memset(s2,0,sizeof(s2)); n = strlen(s+1); //puts(s); // printf("%d\n",n); x = n%3; y = n/3; s2[1] = s[3*y+1],s2[2] = s[3*y+2]; // printf("%d %d \n",x,y); for(int i = 1 ; i <= 3*y; i++){ num = s[i] ; if(i%3 == 1){ for(int i = 8; i >= 1; i--){ a[i] = num%2; num/= 2; } } else if(i%3 == 2){ for(int i = 16; i >= 9; i--){ a[i] = num%2; num/= 2; } } else if(i%3 == 0){ for(int i = 24; i >= 17; i--){ a[i] = num%2; num/= 2; } // for(int i = 1; i <= 24; i++) // printf("%d",a[i]); num = 0; for(int i = 1; i <= 24; i++){ if(i%6 == 0){ num = num * 2 + a[i]; s3[flag++] = s1[num]; num = 0; } else { num = num * 2 + a[i]; } } } } // printf("%d",flag); // puts(s+1); if(x == 1){ for(int i = 12; i >= 9; i--) a[i] = 0; num = s2[1]; // printf("%d\n",num); for(int i = 8; i >= 1; i--){ a[i] = num%2; num/= 2; } // for(int i = 1; i <= 8; i++) // printf("%d",a[i]); num = 0; for(int i = 1; i <= 12; i++){ if(i%6 == 0 ){ num = num*2 + a[i]; // printf("%d\n",num); s3[flag++] = s1[num]; // printf("%c",s[1]); num = 0; } else num = num*2 + a[i]; } s3[flag++] = ‘=‘; s3[flag++] = ‘=‘; } else if(x == 2){ for(int i = 18; i >= 17; i--) a[i] = 0; num = s2[2]; for(int i = 16; i >= 9; i--){ a[i] = num%2; num/= 2; } num = s2[1] ; // printf("%c\n",s2[1]); //printf("%c\n",s2[2]); for(int i = 8; i >= 1; i--){ a[i] = num%2; num/=2; } num = 0; for(int i = 1; i <= 18; i++){ if(i%6 == 0 ){ num = num*2 + a[i]; s3[flag++] = s1[num]; num = 0; } else num = num * 2 + a[i]; } s3[flag++] = ‘=‘; } // puts(s3+1); strcpy(s+1,s3+1); // puts(s+1); memset(s3,0,sizeof(s3)); } int main() { int n,num; scanf("%d",&T); for(int cas = 1; cas <= T; cas++){ memset(s,0,sizeof(s)); memset(s2,0,sizeof(s2)); scanf("%d",&k); getchar(); gets(s+1); //puts(s+1); for(int i = 1; i <= k;i++){ // puts(s+1); base(); } printf("Case #%d: ",cas); for(int i = 1; i < flag ; i++) printf("%c",s[i]); puts(""); } return 0; }
标签:
原文地址:http://www.cnblogs.com/zero-begin/p/4532161.html