当前位置:网站首页>LeetCode-1078. Bigram participle
LeetCode-1078. Bigram participle
2022-06-12 06:22:00 【Border wanderer】
Give the first word first And the second word second, Consider in some texts text It is possible that "first second third" What happens in the form of , among second In the wake of first appear ,third In the wake of second appear .
For each such case , Put the third word "third" Add to the answer , And return the answer .
Example 1:
Input :text = "alice is a good girl she is a good student", first = "a", second = "good"
Output :["girl","student"]
Example 2:
Input :text = "we will we will rock you", first = "we", second = "will"
Output :["we","rock"]
Tips :
1 <= text.length <= 1000
text It consists of lowercase English letters and spaces
text All words in the are separated by Single space character Separate
1 <= first.length, second.length <= 10
first and second It's made up of lowercase letters
#include<iostream>
#include<vector>
#include<unordered_map>
using namespace std;
class Solution {
public:
vector<string> findOcurrences(string text, string first, string second) {
unordered_map<string, bool> hash;
vector<string> vec;
text.push_back(' ');
string key = first + ' ' + second;
cout << "key:" << key << endl;
splitstr(vec, text, key);
return vec;
}
/* It needs to be counted twice */
void splitstr(vector<string>& vec, string &text, string& key) {
int start = 0;
int laststart = 0;
int index = 0;
string tmpstr;
int count = 0; /* Count the number of spaces */
for (char c : text) {
if (c == ' ') {
count++;
if (count == 1) {
laststart = index;
}
if (count == 2) {
tmpstr = text.substr(start, index - start);
start = laststart + 1;
laststart = index;
count = 1;
cout << "tmpstr1:" << tmpstr << endl;
findThird(vec, tmpstr, text, key,index);
}
}
index++;
}
}
void findThird(vector<string>& vec, string &tmpstr, string&text, string& key, int index) {
if (tmpstr == key) {
cout << "in" << endl;
for (int i = index + 1; i < text.size(); i++) {
if (text[i] == ' ') {
string third = text.substr(index + 1, i - index - 1);
cout << "third:" << third << endl;
vec.emplace_back(third);
break;
}
}
}
}
};边栏推荐
猜你喜欢

Modifying theme styles in typora

Multithreading (V) -- concurrency tools (I) -- thread pool (II) -- related contents of ThreadPoolExecutor

. Net core - pass Net core will Net to cross platform

Leetcode-1535. Find the winner of the array game

Redis configuration (III) -- master-slave replication

Cause analysis of motion blur / smear caused by camera shooting moving objects

Unity implements smooth interpolation

IBL of directx11 advanced tutorial PBR (3)

Chartextcnn (Ag dataset - news topic classification)

Getting started with houdininengine HDA and UE4
随机推荐
. Net core and Net framework comparison
Word2Vec
RNN implementation regression model
JS变量作用域
Multithreading mode (I) -- protective pause and join source code
MNIST handwritten data recognition by RNN
(UE4 4.27) add globalshder to the plug-in
Unity3d multi platform method for reading text files in streamingasset directory
Book classification based on Naive Bayes
Jetson TX2 machine brushing jetpack4.2 (self test successful version)
Automatic modeling of Interchange
Unity3d display FPS script
Solution to the problem of the 80th fortnight competition of leetcode
关于 Sensor flicker/banding现象的解释
Getting started with houdininengine HDA and UE4
Three years of sharpening a sword: insight into the R & D efficiency of ant financial services
(UE4 4.27) UE4 adds a customized meshpass to realize the edge illumination of the mobile terminal
Nodemon cannot load the file c:\users\administrator\appdata\roaming\npm\nodemon PS1, because script execution is prohibited in this system
Redis data type (VII) -- hyperloglog
Cross compile libev