题解 | #单词倒排#

单词倒排

http://www.nowcoder.com/practice/81544a4989df4109b33c2d65037c5836

读入一行字符串,正则遍历找出符合要求的子串,压入栈,输出(出栈)直到栈空。

#include <iostream>
#include <string>
#include <regex>
#include <stack>
using namespace std;
int main ()
{
    string str; 
    stack<string> tmp;
    getline(cin,str);
    regex regstring("[A-Za-z]+");
    for(sregex_iterator it(str.begin(),str.end(),regstring),it_end; it!=it_end; ++it)    
    {
        tmp.push(it -> str());   //将符合要求的字符串压入栈 
    }
    while(!tmp.empty())
    {
        cout<<tmp.top()<<' '; //栈反向输出
        tmp.pop();  //pop-1 
    }
    return 0;
}
全部评论

相关推荐

点赞 评论 收藏
分享
身边有人上海、深圳&nbsp;6、7k&nbsp;都去了,真就带薪上班了。
程序员小白条:木的办法, 以后越来越差,还是家附近宅着吧,毕业的人越来越多,岗位都提供不出来,经济又过了人口红利期
点赞 评论 收藏
分享
评论
1
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务