字符串01

344. 反转字符串

class Solution {
public:
    void reverseString(vector<char>& s) {
        int n = s.size();
        cout << n;
        int count = 0;
        while(count < n / 2)
        {
            char tmp = s[count];
            s[count] = s[n - count -1];
            s[n - count - 1] = tmp;
            count++;
        }
    }
};

541. 反转字符串 II

class Solution {
public:
     
    string reverseStr(string s, int k) {
        int n = s.size();
        for(int i = 0; i < n; i += 2 * k)
        {
           reverse(s.begin() + i, s.begin() + min(i + k, n));
        }
        return s;
    }
};

54. 替换数字(第八期模拟笔试)

#include <iostream>
#include <string>

using namespace std;

string s;
int main()
{
    cin >> s;
    string answer;
    for(int i = 0; i < s.size(); i++)
    {
        if(isdigit(s[i]))
        {
            answer += "number";
        }
        else
            answer += s[i];
    }
    cout << answer;
    return 0;
}
posted @ 2025-07-15 20:42  skyler886  阅读(10)  评论(0)    收藏  举报