zoukankan      html  css  js  c++  java
  • [华为]句子逆序

    题目描述:将一个英文语句以单词为单位逆序排放。例如“I am a boy”,逆序排放后为“boy a am I”

    所有单词之间用一个空格隔开,语句中除了英文字母外,不再包含其他字符


    接口说明

    /**
     * 反转句子
     * 
     * @param sentence 原句子
     * @return 反转后的句子
     */
    public String reverse(String sentence);

    输入描述:将一个英文语句以单词为单位逆序排放。
    输出描述:得到逆序的句子
    输入例子:I am a boy
    输出例子:boy a am I
     1 #include<iostream> 
     2 #include<stack> 
     3 #include<string> 
     4 using namespace std; 
     5 int main() 
     6 { 
     7       stack<string> ss; 
     8       string s; 
     9       while(cin>>s) 
    10       { 
    11           ss.push(s); 
    12       } 
    13       while(!ss.empty()) 
    14       { 
    15           cout<<ss.top(); 
    16           ss.pop(); 
    17           if(!ss.empty()) 
    18               cout<<' '
    19       } 
    20       cout<<endl;
    21 }
     1 #include<iostream>
     2 #include<vector>
     3 using namespace std;
     4 int main()
     5 {    
     6     string s;    
     7     vector<string> vs;   
     8     while(cin >> s)        
     9         vs.push_back(s);    
    10     for(int i = vs.size()-1; i > 0; --i)        
    11         cout << vs[i] << " ";    
    12     cout << vs[0] << endl;    
    13     return 0;
    14 }
  • 相关阅读:
    flash 语法 入门
    flash 代码 雪花飘落
    test windows live writer
    网站索引
    [转]jquery入门简介
    forcast iframe 及 四款播放器
    flash
    flash 备忘
    浏览器默认HTML的CSS样式属性
    简单多线程拷贝单文件示例
  • 原文地址:https://www.cnblogs.com/hellochennan/p/6667558.html
Copyright © 2011-2022 走看看