Skip to main content

Posts

Showing posts with the label Reverse words in a given string

Reverse words in a given String

Task: Reverse the entire string without reverse individual words, which is consisting of words with separated by dots. Example: Input: i.like.this.program.very.much Output: much.very.program.this.like.i Here is the Code: Program in C++: #include <iostream> #include <bits/stdc++.h> using namespace std; string reverseWords(string s) {     stack<char> st;     int c=0;     //reverse individual words     for(int i=0;i<s.length();i++)     {         if(s[i]=='.')         {             //back to starting position             //of current word             i=i-c;             while(st.empty()==false)             {                 s[i]=st.top();                 st...