本人菜鸟,记录一下自己的学习笔记
#include
#include
using namespace std;
//字符串局部逆置算法
int Re(string &n, int a, int b)
{
if (n.length() == 0 || a > n.length() || b > n.length())
{
return -1;
}
int count = (b - a + 1) / 2;
char n1;
while(count)
{
n1 = n[a];
n[a] = n[b];
n[b] = n1;
count--,a++,b--;
}
}
//根据识别字符串中的大小写去逆置
void AaStrRe(string &n)
{
vector flag_vector;
flag_vector.clear();
for (int i = 0; i < n.length(); i++)
{
if (n[i] < 97)
{
flag_vector.push_back(i);
}
}
//补充最后一位
flag_vector.push_back(n.length());
for (int i = 0; i < flag_vector.size() - 1; i++)
{
Re(n, flag_vector[i], flag_vector[i + 1] - 1);
}
}
int main()
{
string str1 = “NiHaoWorld”, str2 = “12345678”,str3 = “NiShiDaShaZi”;
AaStrRe(str3);
cout << str3 << endl;;
system("pause");
}