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 3n lowercase letter.The binary ascii string of s is a string consist of 83n 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 83*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
题解
题意:将给定字符串的每个字符的ASCII码转八位二进制并倒置,总的二进制串每六位转十进制输出。
思路:模拟即可,注意输出格式为每个数字跟一个空格且无换行。
我觉的这题的精髓在于空间,
比赛的时候我数组开小了,一直提示tle,然后看了大佬的博客才知道哪里错了。
当然代码是我自己修改的之前错的,这次真的没有抄代码。
大佬的原博客
#include <bits/stdc++.h>
using namespace std;
const int maxn=1e5+5;
char a[3*maxn+10];
int b[24*maxn+10];
int main()
{
int len,i,t=0,n,x;
int c[6]= {1,2,4,8,16,32};
scanf("%s",a);
len=strlen(a);
memset(b,0,sizeof(b));
for(i=0; i<len; i++)
{
n=a[i];
int t1=i*8;
while(n>0)
{
x=n%2;
n=n/2;
b[t1++]=x;
}
}
t=len*8;
for(i=5; i<=t-1; i+=6)
{
n=b[i]*c[0]+b[i-1]*c[1]+b[i-2]*c[2]+b[i-3]*c[3]+b[i-4]*c[4]+b[i-5]*c[5];
printf("%d ",n);
}
return 0;
}