代码编织梦想

Lowbit

在这里插入图片描述

#include <bits/stdc++.h>
#define deb2(x, y) cout << #x << "=" << x << ", " << #y << "=" << y << endl
using namespace std;

int main() {
    string s; cin >> s;
    
    reverse(s.begin(), s.end());
    s += "00";
    
    int j =0, cnt = 0;
    for (int i = 0; i < s.size()+1; i ++ ) {
        if(s[i] == '1' && s[i+1] == '0') cnt += 1;
        if(s[i] == '1' && s[i+1] == '1') {
            j = i + 1, s[i] = '0';
            while(j < s.size() && s[j] == '1') {
                s[j] = '0', j ++ ;
            }
//             cout << i << ' ' << j << endl;
            s[j] = '1', i = j - 1, cnt += 1;
        }
    }
    cout << cnt;
}

Homework

在这里插入图片描述

#include <bits/stdc++.h>

using namespace std;

int main() {
    ios::sync_with_stdio(false); cin.tie(0), cout.tie(0);
    int n; cin >> n;
    int maxn_a = 0, maxn_c = 0, x = 0;
    for (int i = 1; i <= n; i ++ ) {
        cin >> x;
        maxn_a = max(maxn_a, x);
    }
    long long sum = 0;
    for (int i = 1; i <= n; i ++ ) {
        cin >> x;
        sum += x;
        maxn_c = max(maxn_c, x);
    }
    cout << (long long)(maxn_a + sum - maxn_c);
}
版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/m0_63216173/article/details/131027182