Skip to content

Commit 942ff37

Browse files
committed
test: 3602, 3603, 3604, 3605 solution
py
1 parent 78029f5 commit 942ff37

34 files changed

+1131
-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
{
22
"daily": "1865",
3-
"plans": ["3597", "problems", "3598", "problems", "3599", "problems", "3600", "problems"]
3+
"plans": ["3602", "problems", "3603", "problems", "3604", "problems", "3605", "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_1865"
4+
problem "leetCode/problems/problems_3602"
55
"testing"
66
)
77

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

problems/problems_3602/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 concatHex36(int n) {
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+
int n = json::parse(inputArray.at(0));
27+
return solution.concatHex36(n);
28+
}

problems/problems_3602/Solution.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package problems.problems_3602;
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 concatHex36(int n) {
10+
11+
}
12+
13+
@Override
14+
public Object solve(String[] inputJsonValues) {
15+
int n = Integer.parseInt(inputJsonValues[0]);
16+
return JSON.toJSON(concatHex36(n));
17+
}
18+
}

problems/problems_3602/problem.md

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
# 3602. Hexadecimal and Hexatrigesimal Conversion
2+
3+
<p>You are given an integer <code>n</code>.</p>
4+
5+
<p>Return the concatenation of the <strong>hexadecimal</strong> representation of <code>n<sup>2</sup></code> and the <strong>hexatrigesimal</strong> representation of <code>n<sup>3</sup></code>.</p>
6+
7+
<p>A <strong>hexadecimal</strong> number is defined as a base-16 numeral system that uses the digits <code>0 &ndash; 9</code> and the uppercase letters <code>A - F</code> to represent values from 0 to 15.</p>
8+
9+
<p>A <strong>hexatrigesimal</strong> number is defined as a base-36 numeral system that uses the digits <code>0 &ndash; 9</code> and the uppercase letters <code>A - Z</code> to represent values from 0 to 35.</p>
10+
11+
<p>&nbsp;</p>
12+
<p><strong class="example">Example 1:</strong></p>
13+
14+
<div class="example-block">
15+
<p><strong>Input:</strong> <span class="example-io">n = 13</span></p>
16+
17+
<p><strong>Output:</strong> <span class="example-io">&quot;A91P1&quot;</span></p>
18+
19+
<p><strong>Explanation:</strong></p>
20+
21+
<ul>
22+
<li><code>n<sup>2</sup> = 13 * 13 = 169</code>. In hexadecimal, it converts to <code>(10 * 16) + 9 = 169</code>, which corresponds to <code>&quot;A9&quot;</code>.</li>
23+
<li><code>n<sup>3</sup> = 13 * 13 * 13 = 2197</code>. In hexatrigesimal, it converts to <code>(1 * 36<sup>2</sup>) + (25 * 36) + 1 = 2197</code>, which corresponds to <code>&quot;1P1&quot;</code>.</li>
24+
<li>Concatenating both results gives <code>&quot;A9&quot; + &quot;1P1&quot; = &quot;A91P1&quot;</code>.</li>
25+
</ul>
26+
</div>
27+
28+
<p><strong class="example">Example 2:</strong></p>
29+
30+
<div class="example-block">
31+
<p><strong>Input:</strong> <span class="example-io">n = 36</span></p>
32+
33+
<p><strong>Output:</strong> <span class="example-io">&quot;5101000&quot;</span></p>
34+
35+
<p><strong>Explanation:</strong></p>
36+
37+
<ul>
38+
<li><code>n<sup>2</sup> = 36 * 36 = 1296</code>. In hexadecimal, it converts to <code>(5 * 16<sup>2</sup>) + (1 * 16) + 0 = 1296</code>, which corresponds to <code>&quot;510&quot;</code>.</li>
39+
<li><code>n<sup>3</sup> = 36 * 36 * 36 = 46656</code>. In hexatrigesimal, it converts to <code>(1 * 36<sup>3</sup>) + (0 * 36<sup>2</sup>) + (0 * 36) + 0 = 46656</code>, which corresponds to <code>&quot;1000&quot;</code>.</li>
40+
<li>Concatenating both results gives <code>&quot;510&quot; + &quot;1000&quot; = &quot;5101000&quot;</code>.</li>
41+
</ul>
42+
</div>
43+
44+
<p>&nbsp;</p>
45+
<p><strong>Constraints:</strong></p>
46+
47+
<ul>
48+
<li><code>1 &lt;= n &lt;= 1000</code></li>
49+
</ul>

problems/problems_3602/problem_zh.md

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# 3602. 十六进制和三十六进制转化
2+
3+
<p>给你一个整数 <code>n</code>。</p>
4+
5+
<p>返回 <code>n<sup>2</sup></code> 的&nbsp;<strong>十六进制表示</strong> 和 <code>n<sup>3</sup></code> 的&nbsp;<strong>三十六进制表示</strong> 拼接成的字符串。</p>
6+
7+
<p><strong>十六进制&nbsp;</strong>数定义为使用数字 <code>0 – 9</code> 和大写字母 <code>A - F</code> 表示 0 到 15 的值。</p>
8+
9+
<p><strong>三十六进制&nbsp;</strong>数定义为使用数字 <code>0 – 9</code> 和大写字母 <code>A - Z</code> 表示 0 到 35 的值。</p>
10+
11+
<p>&nbsp;</p>
12+
13+
<p><strong class="example">示例 1:</strong></p>
14+
15+
<div class="example-block">
16+
<p><strong>输入:</strong><span class="example-io">n = 13</span></p>
17+
18+
<p><strong>输出:&nbsp;</strong><span class="example-io">"A91P1"</span></p>
19+
20+
<p><strong>解释:</strong></p>
21+
22+
<ul>
23+
<li><code>n<sup>2</sup> = 13 * 13 = 169</code>。在十六进制中,它转换为 <code>(10 * 16) + 9 = 169</code>,对应于 <code>"A9"</code>。</li>
24+
<li><code>n<sup>3</sup> = 13 * 13 * 13 = 2197</code>。在三十六进制中,它转换为 <code>(1 * 36<sup>2</sup>) + (25 * 36) + 1 = 2197</code>,对应于 <code>"1P1"</code>。</li>
25+
<li>连接两个结果得到 <code>"A9" + "1P1" = "A91P1"</code>。</li>
26+
</ul>
27+
</div>
28+
29+
<p><strong class="example">示例 2:</strong></p>
30+
31+
<div class="example-block">
32+
<p><strong>输入:</strong><span class="example-io">n = 36</span></p>
33+
34+
<p><strong>输出:</strong><span class="example-io">"5101000"</span></p>
35+
36+
<p><strong>解释:</strong></p>
37+
38+
<ul>
39+
<li><code>n<sup>2</sup> = 36 * 36 = 1296</code>。在十六进制中,它转换为 <code>(5 * 16<sup>2</sup>) + (1 * 16) + 0 = 1296</code>,对应于 <code>"510"</code>。</li>
40+
<li><code>n<sup>3</sup> = 36 * 36 * 36 = 46656</code>。在三十六进制中,它转换为 <code>(1 * 36<sup>3</sup>) + (0 * 36<sup>2</sup>) + (0 * 36) + 0 = 46656</code>,对应于 <code>"1000"</code>。</li>
41+
<li>连接两个结果得到 <code>"510" + "1000" = "5101000"</code>。</li>
42+
</ul>
43+
</div>
44+
45+
<p>&nbsp;</p>
46+
47+
<p><strong>提示:</strong></p>
48+
49+
<ul>
50+
<li><code>1 &lt;= n &lt;= 1000</code></li>
51+
</ul>

problems/problems_3602/solution.go

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

problems/problems_3602/solution.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import string
2+
from collections import deque
3+
4+
import solution
5+
from typing import *
6+
7+
8+
class Solution(solution.Solution):
9+
def solve(self, test_input=None):
10+
return self.concatHex36(test_input)
11+
12+
def concatHex36(self, n: int) -> str:
13+
x, y = n ** 2, n ** 3
14+
ans = deque()
15+
while y:
16+
ans.appendleft(S[y % 36])
17+
y //= 36
18+
while x:
19+
ans.appendleft(S[x % 16])
20+
x //= 16
21+
return ''.join(ans)
22+
23+
S = string.digits + string.ascii_uppercase

problems/problems_3602/testcase

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
["13", "36"]
2+
["A91P1", "5101000"]

problems/problems_3602/testcase.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
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=13, Output="A91P1"))
11+
self.testcases.append(case(Input=36, Output="5101000"))
12+
13+
def get_testcases(self):
14+
return self.testcases

0 commit comments

Comments
 (0)