LintCode 53 翻转字符串
2017-04-29 09:53
176 查看
题目:reverseWords
要求:
给定一个字符串,逐个翻转字符串中的每个单词。样例:
单词的构成:无空格字母构成一个单词输入字符串是否包括前导或者尾随空格?可以包括,但是反转后的字符不能包括
如何处理两个单词间的多个空格?在反转字符串中间空格减少到只含一个
算法要求:
无解题思路:
用strtok进行字符串分割。算法如下:
string reverseWords(string s) { // write your code here stringstream in; stringstream out; in << s; char str[101][101]; char tempStr[1001]; in.getline(tempStr, 1001); int num = 0; char *t = NULL; for (t = strtok(tempStr, " "); t != NULL; t = strtok(NULL, " ")) { strcpy(str[num++], t); } for (int i = num - 1; i >= 0; i--) { out << str[i] << " "; } return out.str(); }
相关文章推荐
- [LintCode]53.翻转字符串
- LintCode-剑指Offer-(53)翻转字符串
- [Lintcode] #53 翻转字符串
- LintCode【简单】53. 翻转字符串 。代码及思路
- LintCode-53.翻转字符串
- LintCode 53. 翻转字符串
- LintCode- 翻转字符串
- 日常练习:lintcode 53. 翻转字符串
- LintCode 第53题 翻转字符串
- 容易_53_翻转字符串(2)
- LintCode(easy)翻转字符串
- lintcode,翻转字符串
- 【LintCode】Reverse Words in a String 翻转字符串
- 翻转字符串(LintCode)
- [LintCode] Reverse Words in a String 翻转字符串中的单词
- LintCode_053_翻转字符串
- 【LintCode】Reverse Words in a String 翻转字符串
- LintCode_053_翻转字符串
- LintCode之53 翻转字符串
- LintCode 算法(简单)翻转字符串