英文句子中的单词逆序
2014-06-07 16:22
225 查看
#include "stdafx.h" #include <iostream> #include <string> #include <stack> using namespace std; int main(int arc, char** argv) { string str="I come from liaoning."; stack<string> works; int len=str.length(); while(1) { int start=str.find_first_not_of(" "); int end=str.find_first_of(" "); int wlen=end-start; if(end!=-1) { string temp=str.substr(start,wlen); works.push(temp); } else { works.push(str); break; } str=str.substr(end+1,len-wlen); } while(!works.empty()) { string temp=works.top(); cout<<temp<<" "; works.pop(); } cout<<endl; system("pause"); return 0; }
相关文章推荐
- 输入一个英文句子,按单词逆序输出
- C++实现英文句子中的单词逆序输出的方法
- Java实现英文句子中的单词顺序逆序输出的方法
- java逆序英文句子中的单词顺序
- 软件工程导论课后习题Github作业(把一个英文句子中的单词次序逆序,单词中字母正常排列)
- C++ 实现句子中单词逆序输出
- 对某一个英文句子中所有单词倒置
- 每天学习一点编程(2)(输入一个英文句子,翻转句子中单词的顺序,但单词内字符的顺序不变)
- 题目:输入一个英文句子,翻转句子中单词的顺序,但单词内字符的顺序不变。句子中单词以空格符隔开。为简单起见,标点符号和普通字母一样处理。例如输入“I am a student.”,则输出“student
- java算法实现之--输入一个英文句子,翻转句子中的单词顺序,但单词内字符的顺序不变
- 将句子的单词顺序逆序
- 句子中的单词逆序输出和归并排序
- 句子以单词为单位逆序
- PAT乙级 1009. 说反话 (20) 句子中单词逆序输出,'\0'的妙用,字符串分割
- 面试题:输入一个英文句子,翻转句子中单词的顺序,但单词内字符的顺序不变。句子中单词以空格符隔开。
- 牛客最近来了一个新员工Fish,每天早晨总是会拿着一本英文杂志,写些句子在本子上。同事Cat对Fish写的内容颇感兴趣,有一天他向Fish借来翻看,但却读不懂它的意思。例如,“student. a am I”。后来才意识到,这家伙原来把句子单词的顺序翻转了,正确的句子应该是“I am a student.”。Cat对一一的翻转这些单词顺序可不在行,你能帮助他么?
- 计算一条英文句子中单词个数
- 输入一个英文句子,将每个单词的第一个字母改成大写字母。
- 将英文句子拆成一个个单词(对于句子中可能出现的不同情况)
- water || 算英文句子中单词个数