标签:ram word .com img return ever ret strtok rto
代码(C++):
class Solution {
public:
/**
* @param s : A string
* @return : A string
*/
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();
}
};
标签:ram word .com img return ever ret strtok rto
原文地址:http://www.cnblogs.com/majixian/p/7221835.html