1 int main() { 2 Solution s; 3 for (auto c : s.generateParenthesis(3)) 4 cout << c << " "; // ((())) (()()) (())() ()(()) ()()() 5 }
1 #include "pch.h" 2 #include <iostream> 3 #include <string> 4 #include <vector> 5 #include <algorithm> 6 using namespace std; 7 8 int main() { 9 string word; 10 vector<string> text; 11 12 while (cin >> word && word !="0") // 依次读入单个string 13 text.push_back(word); 14 15 sort(text.begin(), text.end()); 16 17 for (int n = 0; n < text.size(); n++) // 依次输出单个string,不能直接cout<<text!!! 18 cout << text[n] << " "; 19 }
1 #include "pch.h" 2 #include <iostream> 3 #include <string> 4 #include <vector> 5 #include <algorithm> 6 #include <iterator> 7 8 using namespace std; 9 10 int main() { 11 string word; 12 vector<string> text; 13 14 while (cin >> word && word != "0") 15 text.push_back(word); 16 17 sort(text.begin(), text.end()); 18 19 ostream_iterator<string> outputos(cout, " "); // 将outputos绑至标准输出 20 copy(text.begin(), text.end(), outputos); // copy()会将存在text中的每个元素依次写到由outputos所表示的ostream上输出。 21 }
原文:https://www.cnblogs.com/kongzimengzixiaozhuzi/p/13059849.html