Complete the solution so that it splits the string into pairs of two characters. If the string contains an odd number of characters then it should replace the missing second character of the final pair with an underscore ('_').
将字符串拆分为两个字符为一对,不足两个字符的,补齐一个下标('_')
#include <string>
#include <vector>
#include<iostream>
using namespace std;
std::vector<std::string> solution(const std::string &s)
{
string se{ s };
vector<std::string> st;
if (s.length() % 2 != 0)
se.push_back('_');
//cout << s.length() << endl;
for (int i = 0; i < se.length() ; i+=2) {
st.push_back(se.substr(i, 2));
}
return st;
//return {}; // Your code here
}