hdu5237 Base64(模拟)
来源:互联网 发布:保山学院网络教学平台 编辑:程序博客网 时间:2024/06/01 07:27
题目链接:
http://acm.hdu.edu.cn/showproblem.php?pid=5237
题目大意:
只需要实现将原字符串每三字节24位重新切分为4个6位,然后从表里转换为对应的BASE64码即可,不足三字节的用0补满至下一个6位(即剩一个字节补4个0补成12位,剩下两个字节补2个0补成18位),然后用'='补齐剩下的空位即可。
思路:
题意懂了,就知道怎么做了。。。。
我的缺点就是,拖拉机代码。。其实很多都可以写到一个函数里面,真是。。连自己都嫌弃自己了。。。
但还是贴上来了( ▼-▼ )
代码:
#include<stdio.h> #include<string.h> #include<math.h> char s[105],str[100005]; int a[3000],qq[10]; char h[]={'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T', 'U','V','W','X','Y','Z','a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p', 'q','r','s','t','u','v','w','x','y','z','0','1','2','3','4','5','6','7','8','9','+','/' }; int quickpow(int a,int b) { // if(b==0)return 0; int ans=1; while(b) { if(b%2)ans=ans*a; a=a*a; b=b/2; } return ans; } void get2(int q) { int i=8; while(q) { qq[i]=q%2; q=q/2; i--; } for(int j=0;j<=i;j++) qq[j]=0; } void zhantie(int k) { for(int i=1;i<=8;i++) {a[i+8*k]=qq[i]; } } void work(int l) { memset(qq,0,sizeof(qq)); memset(a,0,sizeof(a)); int i,j,k,q,aa; i=j=k=q=0; int x; x=l; int as=0; while(x) { q=0; j=0; k=0; if(x>=3) { aa=1; j=0; while(aa<=3) { get2(s[i]); zhantie(j); j++; aa++; i++; } aa=1; while(aa<=4) { int ans=0; for(j=1;j<=6;j++) ans+=a[j+k*6]*quickpow(2,6-j); str[as++]=h[ans]; k++; q++; aa++; } x=x-3; } else if(x==2) { memset(a,0,sizeof(a)); memset(qq,0,sizeof(qq)); aa=1; while(aa<=2) { get2(s[i]); zhantie(j); j++; aa++; i++; } aa=1; while(aa<=3) { int ans=0; for(j=1;j<=6;j++) ans+=a[j+k*6]*quickpow(2,6-j); str[as++]=h[ans]; k++; q++; aa++; } str[as++]='='; x=x-2; } else if(x==1) { memset(a,0,sizeof(a)); memset(qq,0,sizeof(qq)); aa=1; while(aa<=1) { get2(s[i]); zhantie(j); j++; aa++; i++; } aa=1; while(aa<=2) { int ans=0; for(j=1;j<=6;j++) ans+=a[j+k*6]*quickpow(2,6-j); str[as++]=h[ans]; k++; q++; aa++; } str[as++]='='; str[as++]='='; x=x-1; } } } int main() { int T,i,j,k,n,l,shu,icase=0; scanf("%d",&T); while(T--) { memset(str,0,sizeof(str)); icase++; scanf("%d%s",&n,s); strcpy(str,s); while(n--) { l=strlen(str); memset(qq,0,sizeof(qq)); memset(a,0,sizeof(a)); work(l); strcpy(s,str); s[strlen(s)]='\0'; } printf("Case #%d: ",icase); printf("%s\n",str); } }
0 0
- hdu5237 Base64(模拟)
- HDU5237 Base64 大模拟
- hdu5237-字符串模拟&细节-Base64
- HDU5237- Base64
- HDU 5237-Base64(模拟-K轮加密)
- base64转码(简单的get方式图片上传,模拟app接收图片)
- Base64编码(1)
- Md5(base64)
- Base64(四)
- base64
- BASE64
- Base64
- BASE64
- Base64
- Base64
- base64
- base64
- base64
- HTML - Amazing HTML
- Linux权限
- plist苹果安装包实现
- 直接修改UIView的x,y,width,height...
- linux下头文件
- hdu5237 Base64(模拟)
- ios截图代码
- nyoj 组合数 32 (dfs)
- python mysql盲注小程序
- Android-Activity
- [iOS]隐藏NavigationBar和StatusBar
- Linux下的文件、文件夹加密方法
- Xocde插件制作小入门
- 一个常用的Android APP框架开发(下)