题解 | #压缩二维码#

压缩二维码

https://www.nowcoder.com/practice/1150d36c2cd64df9bf373988486c6723

#include <bits/stdc++.h>
#include <vector>
const int N = 2e5 + 10;
const int inf = 0x3f3f3f3f;
using namespace std;
using ull = unsigned long long int;
using ll = long long int;

int f(string x){
    int res=0;
    for(int i=0;i<4;i++){
        res+=(x[i]=='#')*(1<<(3-i));
    }
    return res;
}
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin>>n;
    n=(1<<n);
    string ans;
    for(int i=0;i<n;i++){
        string a;
        cin>>a;
        ans+=a;
    }
    n=n*n;
    for(int i=0;i<ans.size();i+=4){
        string x;
        x+=ans[i];
        x+=ans[i+1];
        x+=ans[i+2];
        x+=ans[i+3];
        cout<<f(x)<<" ";
    }
    return 0;
}

二维字符压缩成一维然后每四个字符算一下转二进制的数输出

全部评论
点赞 回复 分享
发布于 2024-11-22 17:00 湖北

相关推荐

05-16 21:54
已编辑
门头沟学院 前端工程师
蓝曦111:我也是25届,这是第二次被裁了,毕业没到一年就失业两次,两次都是公司问题。第一家才转正一个月,跟我说公司拿不到项目结款没办法,赔了一个月;第二个公司连工资都发不出来了,赔偿更别想了,我算是认命了,这条路也不知道能走多远走多久,不过生活还是要继续的,走一步看一步吧
当你面对裁员会如何?
点赞 评论 收藏
分享
评论
5
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务