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

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

从来没有写过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;
}


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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值