Wednesday, December 18, 2019

Reversing words in a String

Sample input String = "Ajitesh is a good boy"
Sample output String="boy good a is Ajitesh"

string wordReverse(string str)
{
    int i = str.length() - 1;
    int start, end = i + 1;
    string result = "";
      
    while(i >= 0)
    {
        if(str[i] == ' ')
        {
            start = i + 1;
            while(start != end)
                result += str[start++];
              
            result += ' ';
              
            end = i;
        }
        i--;
    }
    start = 0;
    while(start != end)
        result += str[start++];
      
    return result;
}
  
// main code
int main()
{
    string str = "Ajitesh is a good boy";
      
    cout << wordReverse(str);
      
    return 0;
}
  

Arrays in Solidity Programming Language.

Arrays Solidity supports both generic and byte arrays. It supports both fixed size and dynamic arrays. It also supports multidimensional ...