#include <iostream>
#include <vector>
using namespace std;
class Solution {
public:
string replaceSpace(string s) {
int l = s.length();
string output;
for (int i = 0; i < l; i++) {
if (s.at(i) != ' ')
{
char temp = s.at(i);
output.push_back(temp);
}
else {
output.push_back('%');
output.push_back('2');
output.push_back('0');
}
}
return output;
}
};
int main()
{
//vector<vector<int>> matrix = { {1,2,3,4,5},{5,6,7,8,9},{9,10,11,12,13} };
string str = "we are happy.";
cout << str << endl;
cout << str.length() << endl;
cout << str.size() << endl;
cout << str.at(4) << endl;
Solution solution;
string output;
output = solution.replaceSpace(str);
cout << output << endl;
return 0;
}
剑指 Offer 05. 替换空格
最新推荐文章于 2022-04-25 15:03:36 发布