File tree Expand file tree Collapse file tree 5 files changed +111
-0
lines changed Expand file tree Collapse file tree 5 files changed +111
-0
lines changed Original file line number Diff line number Diff line change
1
+ string evaluate (string s, vector<vector<string>>& knowledge) {
2
+ int len = knowledge.size ();
3
+ map<string, string> dict;
4
+ for (int i = 0 ; i < len; ++i)
5
+ dict.insert (make_pair (knowledge[i][0 ], knowledge[i][1 ]));
6
+
7
+ stringstream ss;
8
+ int sz = s.size ();
9
+ int i = 0 ;
10
+ while (i < sz)
11
+ {
12
+ if (s[i] != ' (' )
13
+ {
14
+ ss << s[i];
15
+ ++i;
16
+ }
17
+ else
18
+ {
19
+ string key;
20
+ key.reserve (10 );
21
+ int j = i+1 ;
22
+ while (j < sz && s[j] != ' )' )
23
+ {
24
+ key.push_back (s[j]);
25
+ ++j;
26
+ }
27
+ if (dict.find (key) != dict.end ())
28
+ ss << dict[key];
29
+ else
30
+ ss << ' ?' ;
31
+ i = j+1 ;
32
+ }
33
+ }
34
+
35
+ return ss.str ();
36
+ }
Original file line number Diff line number Diff line change
1
+ string firstPalindrome (vector<string>& words) {
2
+ int len = words.size ();
3
+ for (int i = 0 ; i < len; ++i)
4
+ {
5
+ bool flag = true ;
6
+ int sz = words[i].size ();
7
+ for (int j = 0 ; j < sz/2 ; ++j)
8
+ {
9
+ if (words[i][j] != words[i][sz-1 -j])
10
+ {
11
+ flag = false ;
12
+ break ;
13
+ }
14
+ }
15
+ if (flag)
16
+ return words[i];
17
+ }
18
+
19
+ return " " ;
20
+ }
Original file line number Diff line number Diff line change
1
+ int mostWordsFound (vector<string>& sentences) {
2
+ int len = sentences.size ();
3
+ int maxn = 0 ;
4
+ for (int i = 0 ; i < len; ++i)
5
+ {
6
+ int n = count (sentences[i].begin (), sentences[i].end (), ' ' );
7
+ if (n > maxn)
8
+ maxn = n;
9
+ }
10
+
11
+ return maxn+1 ;
12
+ }
Original file line number Diff line number Diff line change
1
+ bool isSameAfterReversals (int num) {
2
+ return num >= 10 ? num%10 != 0 : true ;
3
+ }
Original file line number Diff line number Diff line change
1
+ vector<int > executeInstructions (int n, vector<int >& startPos, string s) {
2
+ int len = s.size ();
3
+ vector<int > res (len, 0 );
4
+ for (int i = 0 ; i < len; ++i)
5
+ {
6
+ int r = startPos[0 ], c = startPos[1 ];
7
+ int j = i;
8
+ for (; j < len; ++j)
9
+ {
10
+ if (s[j] == ' L' )
11
+ {
12
+ if (c == 0 )
13
+ break ;
14
+ --c;
15
+ }
16
+ else if (s[j] == ' R' )
17
+ {
18
+ if (c == n-1 )
19
+ break ;
20
+ ++c;
21
+ }
22
+ else if (s[j] == ' U' )
23
+ {
24
+ if (r == 0 )
25
+ break ;
26
+ --r;
27
+ }
28
+ else
29
+ {
30
+ if (r == n-1 )
31
+ break ;
32
+ ++r;
33
+ }
34
+ }
35
+
36
+ res[i] = j-i;
37
+ }
38
+
39
+ return res;
40
+ }
You can’t perform that action at this time.
0 commit comments