1009. 说反话 (20)


刚写这题 ,没啥思路,不知道该咋办,然后看到网上说二位数组,我就有思路了,然后我用了vector不需要考虑多长是个好处。

容器确实是个好用的东西

#include<bits/stdc++.h>
#include<vector>
using namespace std;
int main()
{
    string s;
    getline(cin,s);
    string t;
    t.clear();
    vector<string>n;
    for(int i=0;s[i];i++)
    {
        if(s[i]==' ')
        {
            n.push_back(t);
            t.clear();//让t为空
        }

        else
            t+=s[i];
    }
    n.push_back(t);
    t.clear();
    vector<string>::iterator iter;
    bool first=false;
    for(iter=n.end()-1;iter>=n.begin();--iter)
    {
        if(first)
            cout<<" ";
        cout<<*iter;
        first=true;
    }
    cout<<endl;
    return 0;

}

猜你喜欢

转载自blog.csdn.net/wchenchen0/article/details/80028372