Skip to content

Commit

Permalink
feat: interview
Browse files Browse the repository at this point in the history
  • Loading branch information
jiangyinzuo committed Aug 3, 2024
1 parent b1293d2 commit 503f6c4
Show file tree
Hide file tree
Showing 7 changed files with 225 additions and 13 deletions.
12 changes: 12 additions & 0 deletions project_files/.vscode/go-debug-single-file.launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"version": "0.2.0",
"configurations": [
{
"name": "Launch file",
"type": "go",
"request": "launch",
"mode": "debug",
"program": "${file}"
}
]
}
15 changes: 3 additions & 12 deletions root/.config/nvim/ftplugin/java.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@
local root_dir = vim.env.PWD

local config = {
cmd = { "jdtls", "--java-executable", vim.g.java_exe_for_jdtls },
cmd = { "jdtls", "--java-executable", vim.g.jdtls_java_exe },
root_dir = root_dir,
init_options = {
bundles = {
-- vscode java debug
vim.fn.glob(
vim.fn.stdpath("data") .. "/mason/packages/java-debug-adapter/extension/server/com.microsoft.java.debug.plugin*.jar"
),
Expand All @@ -18,17 +19,7 @@ local config = {
-- See https://github.com/eclipse/eclipse.jdt.ls/wiki/Running-the-JAVA-LS-server-from-the-command-line#initialize-request
-- And search for `interface RuntimeOption`
-- The `name` is NOT arbitrary, but must match one of the elements from `enum ExecutionEnvironment` in the link above
runtimes = {
-- Ubuntu
{
name = "JavaSE-11",
path = "/lib/jvm/java-11-openjdk-amd64/",
},
{
name = "JavaSE-17",
path = "/lib/jvm/java-17-openjdk-amd64/",
},
}
runtimes = vim.g.jdtls_java_runtimes
}
}
}
Expand Down
1 change: 1 addition & 0 deletions root/.config/nvim/lua/plugins/vimplug.lua
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ local M = {
end,
dependencies = leaderf_dependencies,
},
{ "sebdah/vim-delve", ft = "go" },
}

if vim.g.vimrc_lsp == "coc.nvim" then
Expand Down
182 changes: 182 additions & 0 deletions root/.vim/doc/interview.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,182 @@
vim:ft=help
*interview.txt*

面试前准备:了解编程环境(编译器版本)

算法题解: https://github.com/jiangyinzuo/algorithm

禁用Github Copilot `:Copilot disable`

建立单文件项目

--------------------------------
命令行单文件编译运行 ~

Java: `java Main.java < 1.in`
Python: `python3 a.py < 1.in`

AsyncTask 单文件编译运行 ~

`:AsyncTask file-run`
标准输入重定向 `:AsyncTask file-run-redir`

--------------------------------
单步调试 ~

Java/Python: 先`:DapToggleBreakpoint`, 再`:DapContinue`,在dap-terminal中输入输出

C/Cpp/Rust: `:Termdebug`

Go Dap ~

调试单文件前,在当前目录`.vscode/launch.json`中添加配置(可以通过`:ReadProjectFile`选择`.vscode/go-debug-single-file.launch.json`)
>json
{
"version": "0.2.0",
"configurations": [
{
"name": "Launch file",
"type": "go",
"request": "launch",
"mode": "debug",
"program": "${file}"
}
]
}
<

然后运行`:GoDebug` (go.nvim封装了nvim-dap, 无需配置)

Go Dap支持STDIN比较困难
https://github.com/golang/vscode-go/wiki/debugging#features

Go Delve ~

https://github.com/sebdah/vim-delve

Go调试单文件,标准输入重定向: `:DlvDebug foo.go -r 1.in`

--------------------------------
标准I/O ~

*interview-stdio*

CTRL-D: EOF

来源:牛客网提示

C语言
>c
#include <stdio.h>

int main() {
int a, b;
while (scanf("%d %d", &a, &b) != EOF) {
printf("%d\n", a + b);
}
return 0;
}
<

C++
>cpp
#include <iostream>
using namespace std;

int main() {
int a, b;
while (cin >> a >> b) {
cout << a + b << endl;
}
return 0;
}
<

Java
>java
import java.util.Scanner;

// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
// 注意 hasNext 和 hasNextLine 的区别
while (in.hasNextInt()) { // 注意 while 处理多个 case
int a = in.nextInt();
int b = in.nextInt();
System.out.println(a + b);
}
}
}
<

Python
>python
import sys

for line in sys.stdin:
a = line.split()
print(int(a[0]) + int(a[1]))
<

>python
a, b, c = map(int, input().split())
<

Python EOF
>python
a, b = 0, 0
while True:
try:
a, b = map(int, input().split())
except EOFError:
break
print(a + b)
<

Rust
>rust
use std::io::{self, *};

fn main() {
let stdin = io::stdin();
unsafe {
for line in stdin.lock().lines() {
let ll = line.unwrap();
let numbers: Vec<&str> = ll.split(" ").collect();
let a = numbers[0].trim().parse::<i32>().unwrap_or(0);
let b = numbers[1].trim().parse::<i32>().unwrap_or(0);
print!("{}\n", a + b);
}
}
}
<

Golang的文件名随意,但package name必须是main,这样才能运行`go run foo.go`
>go
package main

import (
"fmt"
)

func main() {
a := 0
b := 0
for {
n, _ := fmt.Scan(&a, &b)
if n == 0 {
break
} else {
fmt.Printf("%d\n", a + b)
}
}
}
<
--------------------------------
DevDocs ~

https://devdocs.io/

cpp openjdk-21

7 changes: 7 additions & 0 deletions root/.vim/doc/java.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
vim:ft=help
*java.txt*

LSP查看JDK源码 ~

Ubuntu 24.04
>bash
apt install openjdk-21-source
<

ubuntu设置java默认路径 ~

方法一
Expand Down
18 changes: 18 additions & 0 deletions root/.vim/tasks.ini
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# Internal Variables
# 可以在本地.task文件中定义[+]secion,替换全局配置中的变量
# See: https://github.com/skywind3000/asynctasks.vim?tab=readme-ov-file#internal-variables
[+]
make_target=

Expand All @@ -22,6 +25,21 @@ output=quickfix
cwd=$(VIM_FILEDIR)
save=2

[file-run-redir]
command="$(VIM_FILEPATH)" < $(-input-file:1.in)
command:c,cpp,rust="$(VIM_PATHNOEXT)" < $(-input-file:1.in)
command:go="$(VIM_PATHNOEXT)" < $(-input-file:1.in)
command:java=java "$(VIM_FILEPATH)" < $(-input-file:1.in)
command:python=python3 "$(VIM_FILENAME)" < $(-input-file:1.in)
command:javascript=node "$(VIM_FILENAME)" < $(-input-file:1.in)
command:sh=sh "$(VIM_FILENAME)" < $(-input-file:1.in)
command:lua=lua "$(VIM_FILENAME)" < $(-input-file:1.in)
command:perl=perl "$(VIM_FILENAME)" < $(-input-file:1.in)
command:ruby=ruby "$(VIM_FILENAME)" < $(-input-file:1.in)
output=terminal
cwd=$(VIM_FILEDIR)
save=2

[file-run]
command="$(VIM_FILEPATH)"
command:c,cpp,rust="$(VIM_PATHNOEXT)"
Expand Down
3 changes: 2 additions & 1 deletion root/.vim/vimrc
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ if has('autocmd') " vim-tiny does not have autocmd
let g:AutoPairsMapCR = 0
let g:nvim_lsp_autostart = {}
let g:vimrc_lsp = get(g:, 'vimrc_lsp', 'nvim-lsp')
let g:java_exe_for_jdtls = get(g:, 'java_exe_for_jdtls', '/usr/bin/java')
let g:jdtls_java_exe = get(g:, 'jdtls_java_exe', '/usr/bin/java')
let g:jdtls_java_runtimes = get(g:, 'jdtls_java_runtimes', [{'name': 'JavaSE-11', 'path': '/usr/lib/jvm/java-11-openjdk-amd64'}, {'name': 'JavaSE-17', 'path': '/usr/lib/jvm/java-17-openjdk-amd64'}])
" speed up loading
let g:python3_host_prog = get(g:, 'python3_host_prog', '/usr/bin/python3')
runtime clipboard_config.lua
Expand Down

0 comments on commit 503f6c4

Please sign in to comment.