Coding Problem

Problem Description

Here is the logic.I am the brother of mata Chuang.Mata chuang is the brother of cxk.So what am I?Am I the grand-brother of cxk?Or am I in a position that same brother level of cxk?Or cxk is the grand-brother of me?
Fine,it doesn't matter to the problem.Problem can't be a problem until it has description.But description are just words.Meaningless words.So,we treat words miserably like this, given a string s consist of 3*n lowercase letter.The binary ascii string of s is a string consist of 8*3*n 0-1 string(one char,8bits,The lower significnt bit is in the front, the higher is in the back.). We want you output the binary ascii string.But we don't want the string too long.So we want you put every 6 bit together(The higher significnt bit is in the front, the lower is in the back.) and output the corresponding array,with a length of 8*3*n/6.Please check the sample for specific.

 

 

Input

one line,one string. (n<=1e5)

 

 

Output

one line,4*n integer representing the target array.

 

 

Sample Input

 

abc

 

 

Sample Output

 

33 36 27 6

Hint

s=abc binary ascii string=10000110 01000110 11000110 answer binary array=100001 100100 011011 000110 final answer array=33 36 27 6

 

 

Source

2019中山大学程序设计竞赛(重现赛)

 

 

Recommend

liuyiding   |   We have carefully selected several similar problems for you:  6521 6520 6519 6518 6517

思路:把字符askmal值转换成二进制存数组然后不足8位补零然后每6位二进制转10进制输出ac

#include<iostream>
#include<cstring>
#include<cmath>
using namespace std;
int v[5000009];
int quickpow(int a,int b)
{
    int ans = 1;
    while(b)
    {
        if(b&1)
        {
            b--;
            ans*=a;
        }
        b>>=1;
        a*=a;
    }
    return ans;
}
int main()
{
    string a;
    cin>>a;
    int t;t = 0;
    for(int i = 0; i < a.length();++i)
    {
        int g = (int)a[i]; 
        while(g)
        {
            v[t] = g%2;
            g>>=1;t++;
        }
        if(t < 8*(i+1))
        {
            v[t] = 0;t++;    
        }    
    }
    int y = 1;
    int sum = 0;int pp = 5;
    for(int i = 0; i < t;++i)
    {
        if(v[i] == 1)
        {
            sum += quickpow(2,pp);
        }
        if(y%6==0)
        {
            printf("%d ",sum);sum = 0;pp = 6;
        }
        y++;
        pp--;
    }
    //printf("\n");
    return 0;
 } 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

-lyslyslys

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值