[C ++] [Algorithm] [String Process] Remind the string in units

xiaoxiao2021-04-09  533

#include

#include

Using namespace std;

///

/// Function name const string stringReverseByword (const string srcstring)

/// The function is in units of words, reverse the string; between words, spaces, as separators

/// parameter const string srcstring needs to process strings processed

// Program keeps the real gate

/// The result of the result is returned in the form of return value.

/// Return Value Const String to reverse the results

///

Const string stringReverseByword (const string srcstring)

{

String result;

INT Pointer = srcstring.Length () - 1;

Int Wordbegin, Wordend, WordLength

While (Pointer> = 0)

{

While (srcstring [Pointer] == '' && Pointer> = 0)

{

Result = "";

Pointer -;

}

Wordend = POINTER;

While (srcstring [Pointer]! = '' && Pointer> = 0)

Pointer -;

Wordbegin = Pointer 1;

WordLength = Wordend - WordBegin 1;

Result = srcstring.substr (WordBegin, WordLength);

}

Return Result;

}

int main ()

{

COUT << StringReverseByword ("I am a student") .c_str () << "." << Endl

Return 0;

}

转载请注明原文地址:https://www.9cbs.com/read-133171.html

New Post(0)