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;
}
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.
    Blogger Comment
    Facebook Comment

0 comments:

Post a Comment