UVA 213 - Message Decoding 简单题 lambda表达式 23333333

时间:2021-08-19 19:08:04

不知道算什么类型才好.......就是按照题意描述读就行了

从来没有写过3个while循环叠在一起......

至于根据号码去找在header里面的下标,其实就是一个二元函数(length,value),length代表长度,value代表本身的值,就相当于一个是段地址,一个是偏移地址,公式是index=((1<<length)-(length+1))+value;

然后用了一个lambda表达式,懒得写函数了

除此之外在读最后000的时候记得把末尾的换行符用cin.get()抽掉

#include <iostream>
#include <string>
#include <algorithm>

using namespace std;
int length,getlength();

string header;
bool getachar();

int main(){
ios_base::sync_with_stdio(false);
while(getline(cin,header)){
while(getlength())
while(getachar());
cout<<endl;
}
return 0;
}

int getlength(){
char c[3];
cin>>c[0]>>c[1]>>c[2];
length=((c[0]-'0')<<2)+((c[1]-'0')<<1)+c[2]-'0';
if(length==0){
cin.get();
return false;
}
return true;
}

bool getachar(){
char c[10]{};
for(int i=0;i<length;++i)
cin>>c[i];
int te=0;
for(int i=0;i<length;++i)
te+=((c[i]-'0')<<(length-i-1));

if([te]()mutable{for(int i=0;i<length;++i,te>>=1)
if(!(te&1))
return false;
return true;
}())
return false;

te=((1<<length)-(length+1))+te;

cout<<header[te];
return true;
}