ZOJ 3713 In 7-bit 解题报告

题目

题意:

给你一些可能包含空格的字符串,对于每个串,计算它的长度,用7位二进制表示,若7位能放完,则第8位为0,否则第8位为1,7位为低7位,然后长度右移7位,继续用7位二进制表示。最后将转换后的长度和原字符串用16进制输出。

解法:

只要读懂了题意,就暴力……

//Time: 350ms
//Memory: 3116KB
//Length: 619B
#include <iostream>
#include <cstdio>
#include <cstring>
#include <queue>
#define MAXN 3000010
#define INF 1000000000
using namespace std;
char str[MAXN];
int main()
{
    //freopen("/home/moor/Code/input.txt","r",stdin);
    int ncase,len,tlen;
    scanf("%d",&ncase);
    gets(str);
    while(ncase--)
    {
        gets(str);
        tlen=len=strlen(str);
        while(1)
        {
            printf("%02X",(len&127)+(len>127?128:0));
            len>>=7;
            if(len==0)  break;
        }
        for(int i=0;i<tlen;++i)
            printf("%02X",(int)str[i]);
        printf("\n");
    }
    return 0;
}



你可能感兴趣的:(ZOJ 3713 In 7-bit 解题报告)