安全问答

安全问答是一个知识全球问答,包含丰富的问答知识

首页 常规 游戏 娱乐 科技 程序员

C++ 实现 01 字符串奇偶位互换

  • 日期: 2024-06-02
  • 标签: 常规
#include <iostream>
#include <string>
using namespace std;

string swapBits(string s) {
    int n = s.length();
    for (int i = 0; i < n; i += 2) {
        swap(s[i], s[i+1]);
    }
    return s;
}

int main() {
    int C;
    cin >> C;
    while (C--) {
        string s;
        cin >> s;
        cout << swapBits(s) << endl;
    }
    return 0;
}

原文地址: https://www.cveoy.top/t/topic/i7II 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录

  • 上一篇: Good morning! Maria I woke up 80 better today I was sweating all night You have a blessed day today You are the best Thanks for asking Maria it means a lot to me that you worried about me
  • 下一篇: 汉中防爆应急灯

© 2019 • 2025 - 安全问答 站长邮箱:wxgpt@qq.com    ICP备案/许可证号:豫ICP备2024104334号-2