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
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;
}