Skip to content

Commit 9774a03

Browse files
committed
test: 3582, 3583, 3584, 3585 solution
py #week454 rank #63
1 parent c7d112d commit 9774a03

34 files changed

+1310
-3
lines changed

daily-problems.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
{
2-
"daily": "316",
2+
"daily": "3585",
33
"plans": ["1", "problems", "LCR_115", "problems"]
44
}

golang/solution_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
package golang
22

33
import (
4-
problem "leetCode/problems/problems_316"
4+
problem "leetCode/problems/problems_3585"
55
"testing"
66
)
77

88
func TestSolution(t *testing.T) {
9-
TestEach(t, "316", "problems", problem.Solve)
9+
TestEach(t, "3585", "problems", problem.Solve)
1010
}

problems/problems_3582/Solution.cpp

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
//go:build ignore
2+
#include "cpp/common/Solution.h"
3+
4+
5+
using namespace std;
6+
using json = nlohmann::json;
7+
8+
class Solution {
9+
public:
10+
string generateTag(string caption) {
11+
12+
}
13+
};
14+
15+
json leetcode::qubh::Solve(string input_json_values) {
16+
vector<string> inputArray;
17+
size_t pos = input_json_values.find('\n');
18+
while (pos != string::npos) {
19+
inputArray.push_back(input_json_values.substr(0, pos));
20+
input_json_values = input_json_values.substr(pos + 1);
21+
pos = input_json_values.find('\n');
22+
}
23+
inputArray.push_back(input_json_values);
24+
25+
Solution solution;
26+
string caption = json::parse(inputArray.at(0));
27+
return solution.generateTag(caption);
28+
}

problems/problems_3582/Solution.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package problems.problems_3582;
2+
3+
import com.alibaba.fastjson.JSON;
4+
import java.util.*;
5+
import qubhjava.BaseSolution;
6+
7+
8+
public class Solution extends BaseSolution {
9+
public String generateTag(String caption) {
10+
11+
}
12+
13+
@Override
14+
public Object solve(String[] inputJsonValues) {
15+
String caption = jsonStringToString(inputJsonValues[0]);
16+
return JSON.toJSON(generateTag(caption));
17+
}
18+
}

problems/problems_3582/problem.md

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
# 3582. Generate Tag for Video Caption
2+
3+
<p>You are given a string <code><font face="monospace">caption</font></code> representing the caption for a video.</p>
4+
5+
<p>The following actions must be performed <strong>in order</strong> to generate a <strong>valid tag</strong> for the video:</p>
6+
7+
<ol>
8+
<li>
9+
<p><strong>Combine all words</strong> in the string into a single <em>camelCase string</em> prefixed with <code>&#39;#&#39;</code>. A <em>camelCase string</em> is one where the first letter of all words <em>except</em> the first one is capitalized. All characters after the first character in <strong>each</strong> word must be lowercase.</p>
10+
</li>
11+
<li>
12+
<p><b>Remove</b> all characters that are not an English letter, <strong>except</strong> the first <code>&#39;#&#39;</code>.</p>
13+
</li>
14+
<li>
15+
<p><strong>Truncate</strong> the result to a maximum of 100 characters.</p>
16+
</li>
17+
</ol>
18+
19+
<p>Return the <strong>tag</strong> after performing the actions on <code>caption</code>.</p>
20+
21+
<p>&nbsp;</p>
22+
<p><strong class="example">Example 1:</strong></p>
23+
24+
<div class="example-block">
25+
<p><strong>Input:</strong> <span class="example-io">caption = &quot;Leetcode daily streak achieved&quot;</span></p>
26+
27+
<p><strong>Output:</strong> <span class="example-io">&quot;#leetcodeDailyStreakAchieved&quot;</span></p>
28+
29+
<p><strong>Explanation:</strong></p>
30+
31+
<p>The first letter for all words except <code>&quot;leetcode&quot;</code> should be capitalized.</p>
32+
</div>
33+
34+
<p><strong class="example">Example 2:</strong></p>
35+
36+
<div class="example-block">
37+
<p><strong>Input:</strong> <span class="example-io">caption = &quot;can I Go There&quot;</span></p>
38+
39+
<p><strong>Output:</strong> <span class="example-io">&quot;#canIGoThere&quot;</span></p>
40+
41+
<p><strong>Explanation:</strong></p>
42+
43+
<p>The first letter for all words except <code>&quot;can&quot;</code> should be capitalized.</p>
44+
</div>
45+
46+
<p><strong class="example">Example 3:</strong></p>
47+
48+
<div class="example-block">
49+
<p><strong>Input:</strong> <span class="example-io">caption = &quot;hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh&quot;</span></p>
50+
51+
<p><strong>Output:</strong> <span class="example-io">&quot;#hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh&quot;</span></p>
52+
53+
<p><strong>Explanation:</strong></p>
54+
55+
<p>Since the first word has length 101, we need to truncate the last two letters from the word.</p>
56+
</div>
57+
58+
<p>&nbsp;</p>
59+
<p><strong>Constraints:</strong></p>
60+
61+
<ul>
62+
<li><code>1 &lt;= caption.length &lt;= 150</code></li>
63+
<li><code>caption</code> consists only of English letters and <code>&#39; &#39;</code>.</li>
64+
</ul>

problems/problems_3582/problem_zh.md

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
# 3582. 为视频标题生成标签
2+
3+
<p>给你一个字符串 <code><font face="monospace">caption</font></code>,表示一个视频的标题。</p>
4+
5+
<p>需要按照以下步骤&nbsp;<strong>按顺序&nbsp;</strong>生成一个视频的&nbsp;<strong>有效标签&nbsp;</strong>:</p>
6+
7+
<ol>
8+
<li>
9+
<p>将 <strong>所有单词&nbsp;</strong>组合为单个&nbsp;<strong>驼峰命名字符串</strong> ,并在前面加上 <code>'#'</code>。<strong>驼峰命名字符串&nbsp;</strong>指的是除第一个单词外,其余单词的首字母大写,且每个单词的首字母之后的字符必须是小写。</p>
10+
</li>
11+
<li>
12+
<p><b>移除&nbsp;</b>所有不是英文字母的字符,但<strong> 保留&nbsp;</strong>第一个字符 <code>'#'</code>。</p>
13+
</li>
14+
<li>
15+
<p>将结果&nbsp;<strong>截断&nbsp;</strong>为最多 100 个字符。</p>
16+
</li>
17+
</ol>
18+
19+
<p>对 <code>caption</code> 执行上述操作后,返回生成的&nbsp;<strong>标签&nbsp;</strong>。</p>
20+
21+
<p>&nbsp;</p>
22+
23+
<p><strong class="example">示例 1:</strong></p>
24+
25+
<div class="example-block">
26+
<p><strong>输入:</strong> <span class="example-io">caption = "Leetcode daily streak achieved"</span></p>
27+
28+
<p><strong>输出:</strong> <span class="example-io">"#leetcodeDailyStreakAchieved"</span></p>
29+
30+
<p><strong>解释:</strong></p>
31+
32+
<p>除了 <code>"leetcode"</code> 以外的所有单词的首字母需要大写。</p>
33+
</div>
34+
35+
<p><strong class="example">示例 2:</strong></p>
36+
37+
<div class="example-block">
38+
<p><strong>输入:</strong> <span class="example-io">caption = "can I Go There"</span></p>
39+
40+
<p><strong>输出:</strong> <span class="example-io">"#canIGoThere"</span></p>
41+
42+
<p><strong>解释:</strong></p>
43+
44+
<p>除了 <code>"can"</code> 以外的所有单词的首字母需要大写。</p>
45+
</div>
46+
47+
<p><strong class="example">示例 3:</strong></p>
48+
49+
<div class="example-block">
50+
<p><strong>输入:</strong> <span class="example-io">caption = "hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh"</span></p>
51+
52+
<p><strong>输出:</strong> <span class="example-io">"#hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh"</span></p>
53+
54+
<p><strong>解释:</strong></p>
55+
56+
<p>由于第一个单词长度为 101,因此需要从单词末尾截去最后两个字符。</p>
57+
</div>
58+
59+
<p>&nbsp;</p>
60+
61+
<p><strong>提示:</strong></p>
62+
63+
<ul>
64+
<li><code>1 &lt;= caption.length &lt;= 150</code></li>
65+
<li><code>caption</code> 仅由英文字母和 <code>' '</code> 组成。</li>
66+
</ul>

problems/problems_3582/solution.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package problem3582
2+
3+
import (
4+
"encoding/json"
5+
"log"
6+
"strings"
7+
)
8+
9+
func generateTag(caption string) string {
10+
11+
}
12+
13+
func Solve(inputJsonValues string) any {
14+
inputValues := strings.Split(inputJsonValues, "\n")
15+
var caption string
16+
17+
if err := json.Unmarshal([]byte(inputValues[0]), &caption); err != nil {
18+
log.Fatal(err)
19+
}
20+
21+
return generateTag(caption)
22+
}

problems/problems_3582/solution.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import solution
2+
from typing import *
3+
4+
5+
class Solution(solution.Solution):
6+
def solve(self, test_input=None):
7+
return self.generateTag(test_input)
8+
9+
def generateTag(self, caption: str) -> str:
10+
words = [s for s in caption.split(" ") if s]
11+
ans = []
12+
for i, w in enumerate(words):
13+
if i == 0:
14+
ans.append(w.lower())
15+
else:
16+
ans.append(w.capitalize())
17+
return ("#"+"".join(ans))[:100]

problems/problems_3582/testcase

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
["\"Leetcode daily streak achieved\"", "\"can I Go There\"", "\"hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh\""]
2+
["#leetcodeDailyStreakAchieved", "#canIGoThere", "#hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh"]

problems/problems_3582/testcase.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
from collections import namedtuple
2+
import testcase
3+
4+
case = namedtuple("Testcase", ["Input", "Output"])
5+
6+
7+
class Testcase(testcase.Testcase):
8+
def __init__(self):
9+
self.testcases = []
10+
self.testcases.append(case(Input="Leetcode daily streak achieved", Output="#leetcodeDailyStreakAchieved"))
11+
self.testcases.append(case(Input="can I Go There", Output="#canIGoThere"))
12+
self.testcases.append(case(Input="hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh", Output="#hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh"))
13+
14+
def get_testcases(self):
15+
return self.testcases

0 commit comments

Comments
 (0)