zoj 3713 In 7-bit

来源:互联网 发布:手机挖矿软件 编辑:程序博客网 时间:2024/06/03 20:33

这道题坑得很惨啊,主要还是纠结于长度的表示,尤其是第三个例子“多出来”的01。不说了,用语言还是表达不出来,还是亮代码吧!

#include<iostream>#include<cstdio>#include<cstring>using namespace std;char s[3000010];int main(){int t,i;scanf("%d",&t);getchar();while(t--){gets(s);int len=strlen(s);if(len==0)printf("00\n");  //不可忽视的一个环节else {int temp=len;while(temp){if(temp>=128){printf("%02X",temp%128+128);temp/=128;}else{printf("%02X",temp);break;}}for(i=0;i<len;i++)printf("%02X",s[i]);printf("\n");}}return 0;}


原创粉丝点击