标签:cto names size color out amp for 数学 运用
怎样将一个字符串中的单词单独存放在一个单词数组里?
#include <iostream>
#include <cstdio>
#include <vector>
#include <sstream>
#include <string>
using namespace std;
int main()
{
string str[100];
string str1 = "i love coding";
stringstream str2(str1);
int i = 0;
string temp;
while (str2 >> temp)
{
str[i++] = temp;
}
for (int j = 0;j < i;j++)
cout << str1[j] << endl;
return 0;
}
运用位运算的方法例举出集合的子集?假设右n个元素
class Solution { public: vector<vector<int>> subsets(vector<int>& nums) { int length=nums.size(); vector<vector<int>> res; for(int i=0;i<(1<<length);i++)//根据数学知道有n个元素的集合共有2^n次方个子集,现在依次例句 { vector<int> temp; for(int j=0;j<length;j++)//检测第j个元素是否在例举之内 { if((i>>j)&1==1) temp.push_back(nums[j]); } res.push_back(temp); } return res; } };
标签:cto names size color out amp for 数学 运用
原文地址:https://www.cnblogs.com/yaggy/p/11332694.html