北邮新OJ103

来源:互联网 发布:淘宝炉石卡包为何便宜 编辑:程序博客网 时间:2024/06/09 02:52

http://code.bupt.edu.cn/problem/p/103/

#include<stdio.h>#include<stdlib.h>#include<string.h>#include<stack>#include<iostream>using namespace std;int main(){    string s;    while(getline(cin,s))    {        stack<string> v;        int f=0;        int l=0;        int len=s.length();        while(l<=len-1)        {            if(s[l]==' ')            {                string tmp=s.substr(f,l-f);                f=l+1;                v.push(tmp);                l++;            }            else                l++;        }        string tmp=s.substr(f,l-f);        v.push(tmp);        int flag=0;        while(v.empty()!=true)        {            string ss=v.top();            v.pop();            if(flag==0)            {                cout<<ss;                flag++;            }            else                cout<<" "<<ss;        }        cout<<endl;    }    return 0;}



0 0
原创粉丝点击