Codeshef CS203 - Can you Reverse Words






#include <bits/stdc++.h>
using namespace std;
int main()
{
    string s="",str,p,st[100];
    getline(cin,str);
    int i,k,l,j=0;
    for(i=0;i<str.length();i++)
    {

        if(str[i]!=' ')
        {
            s=s+str[i];
            //cout<<str[i]<<endl;
            //cout<<s<<endl;

        }
        else
        {
            //s=s+str[i];
            st[j]=s;
            //cout<<j<<st[j]<<endl;
            j++;
            s="";
        }
        p=s;

    }
    st[j]=p;
    //cout<<j<<st[j]<<endl;
    for(k=j;k>=0;k--)
    {
        if(k!=0)
        {
            cout<<st[k]<<" ";
        }
        else
        {
            cout<<st[k]<<endl;
        }

    }


    return 0;
}

Download Coding Interview Book and Get More Tutorials for Coding and Interview Solution: Click Here

Download System Design Interview Book and Get More Tutorials and Interview Solution: Click Here

Do you need more Guidance or Help? Then Book 1:1 Quick Call with Me: Click Here

Share on Google Plus

About Ashadullah Shawon

I am Ashadullah Shawon. I am a Software Engineer. I studied Computer Science and Engineering (CSE) at RUET. I Like To Share Knowledge. Learn More: Click Here
    Blogger Comment
    Facebook Comment

0 comments:

Post a Comment