hud6515 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

就是给你3*n长度的字符串,将每一个字符的ascall码值转化为二进制,组成一个新的字符串,然后每6位二进制输出其对应的十进制数

#include<bits/stdc++.h>
using namespace std;
string turn(char c)//把字符转化为二进制字符串 
{
	bitset<8> b((int)c);//转化为二进制 
	stringstream ss;
	string s;
	ss<<b;ss>>s;//放入流中转化为字符串 
	reverse(s.begin(),s.end());//反转 
	return s;
}
int main()
{
	string s,ts;
	cin>>s;
	int l=s.length(),i;
	for(i=0;i<l;i+=3)
	{
		ts=turn(s[i])+turn(s[i+1])+turn(s[i+2]);
		for(int j=0;j<ts.length();j+=6)
		{
			bitset<6> B(ts,j,6);//取6位 
			printf("%d ",B);//十进制输出 
		}
	}
	return 0;
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值