输入一个句子,如果句子超过30个字,删掉标点符号,跳过一两个字符的单词,删掉句子里面的the 和 and 。
例如
输入: the a apple pan with sugar and vanilla
输出: apple pan with sugar vanilla
可以用cstrings
我尝试了用strlen 但是显示找不到我输入值
输入一个句子,如果句子超过30个字,删掉标点符号,跳过一两个字符的单词,删掉句子里面的the 和 and 。
例如
输入: the a apple pan with sugar and vanilla
输出: apple pan with sugar vanilla
可以用cstrings
我尝试了用strlen 但是显示找不到我输入值
#include<iostream>
#include<cstring>
#include<vector>
using namespace std;
vector<string> split(string str, string pattern)
{
string::size_type pos;
vector<string> result;
str += pattern; //扩展字符串以方便操作
int size = str.size();
for (int i = 0; i < size; i++)
{
pos = str.find(pattern, i);
if (pos < size)
{
string s = str.substr(i, pos - i);
result.push_back(s);
i = pos + pattern.size() - 1;
}
}
return result;
}
int main()
{
string s;
getline(cin, s);
vector<string> result=split(s," ");
for(int i=0; i<result.size(); i++){
if (result[i].size()>2 && result[i]!="the" && result[i]!="and")
cout<<result[i]<<" ";
}
return 0;
}