c#和c++脚本解释器科学运算

news2025/4/8 6:03:00

说明:
我希望用c#和c++写一个脚本解释器,用于科学运算
效果图:
在这里插入图片描述

step1: c#
C:\Users\wangrusheng\RiderProjects\WinFormsApp3\WinFormsApp3\Form1.cs

using System;
using System.Collections.Generic;
using System.Data;
using System.Text;
using System.Text.RegularExpressions;
using System.Windows.Forms;


namespace WinFormsApp3;

public partial class Form1 : Form
{
    private Dictionary<string, double> variables = new Dictionary<string, double>();

    // Windows Forms 设计器代码
    private TextBox txtScript;
    private Button btnExecute;
    private TextBox txtOutput;
    public Form1()
    {
        InitializeComponent();
    
        this.txtScript = new TextBox();
        this.btnExecute = new Button();
        this.txtOutput = new TextBox();
        this.SuspendLayout();
            
        // txtScript
        this.txtScript.Multiline = true;
        this.txtScript.Location = new System.Drawing.Point(12, 12);
        this.txtScript.Size = new System.Drawing.Size(400, 150);
        this.txtScript.ScrollBars = ScrollBars.Vertical;
            
        // btnExecute
        this.btnExecute.Location = new System.Drawing.Point(12, 170);
        this.btnExecute.Size = new System.Drawing.Size(75, 23);
        this.btnExecute.Text = "执行";
        this.btnExecute.Click += new System.EventHandler(this.btnExecute_Click);
            
        // txtOutput
        this.txtOutput.Multiline = true;
        this.txtOutput.Location = new System.Drawing.Point(12, 200);
        this.txtOutput.Size = new System.Drawing.Size(400, 150);
        this.txtOutput.ScrollBars = ScrollBars.Vertical;
        this.txtOutput.ReadOnly = true;
            
        // MainForm
        this.ClientSize = new System.Drawing.Size(424, 361);
        this.Controls.Add(this.txtOutput);
        this.Controls.Add(this.btnExecute);
        this.Controls.Add(this.txtScript);
        this.Text = "简单脚本解释器";
        this.ResumeLayout(false);
        this.PerformLayout();
    }
    
            private void btnExecute_Click(object sender, EventArgs e)
        {
            variables.Clear();
            txtOutput.Clear();
            
            string[] lines = txtScript.Text.Split(
                new[] { "\r\n", "\r", "\n" }, 
                StringSplitOptions.RemoveEmptyEntries
            );

            foreach (string line in lines)
            {
                try
                {
                    var result = ProcessLine(line.Trim());
                    if (!string.IsNullOrEmpty(result))
                    {
                        txtOutput.AppendText(result + "\r\n");
                    }
                }
                catch (Exception ex)
                {
                    txtOutput.AppendText($"错误: {ex.Message}\r\n");
                }
            }
        }

        private string ProcessLine(string line)
        {
            if (string.IsNullOrWhiteSpace(line)) return "";

            // 处理赋值语句
            if (line.Contains("="))
            {
                var match = Regex.Match(line, @"^\s*([a-zA-Z_]\w*)\s*=\s*(.+?)\s*$");
                if (!match.Success) throw new ArgumentException("无效的赋值语句");

                string varName = match.Groups[1].Value;
                double value = EvaluateExpression(match.Groups[2].Value);
                variables[varName] = value;
                return $"{varName} = {value}";
            }

            // 处理普通表达式
            return EvaluateExpression(line).ToString();
        }

        private double EvaluateExpression(string expr)
        {
            // 替换变量为实际值
            string resolvedExpr = Regex.Replace(expr, @"\b([a-zA-Z_]\w*)\b", match =>
            {
                string varName = match.Groups[1].Value;
                if (variables.TryGetValue(varName, out double value))
                {
                    return value.ToString();
                }
                throw new ArgumentException($"未定义的变量: {varName}");
            });

            // 计算数学表达式
            DataTable table = new DataTable();
            table.Columns.Add("expr", typeof(string), resolvedExpr);
            DataRow row = table.NewRow();
            table.Rows.Add(row);
            return Convert.ToDouble(row["expr"]);
        }
    
}

step2: C++代码 C:\Users\wangrusheng\CLionProjects\untitled28\main.cpp

#include <iostream>
#include <string>
#include <map>
#include <regex>
#include <cctype>
#include <vector>
#include <algorithm>
#include <sstream>
#include <stdexcept>

using namespace std;

map<string, double> variables;

// 辅助函数:跳过空白字符
void skip_whitespace(const string& expr, size_t& pos) {
    while (pos < expr.size() && isspace(expr[pos])) pos++;
}

// 表达式解析函数声明
double eval_expression(const string& expr, size_t& pos);
double eval_term(const string& expr, size_t& pos);
double eval_factor(const string& expr, size_t& pos);
double eval_primary(const string& expr, size_t& pos);

// 主解析函数
double evaluate(const string& expr) {
    size_t pos = 0;
    double result = eval_expression(expr, pos);
    skip_whitespace(expr, pos);
    if (pos != expr.size()) {
        throw runtime_error("Unexpected characters in expression");
    }
    return result;
}

// 表达式解析实现
double eval_expression(const string& expr, size_t& pos) {
    return eval_term(expr, pos);
}

double eval_term(const string& expr, size_t& pos) {
    double left = eval_factor(expr, pos);
    skip_whitespace(expr, pos);

    while (pos < expr.size()) {
        char op = expr[pos];
        if (op != '+' && op != '-') break;
        pos++;
        double right = eval_factor(expr, pos);
        if (op == '+') left += right;
        else left -= right;
        skip_whitespace(expr, pos);
    }
    return left;
}

double eval_factor(const string& expr, size_t& pos) {
    double left = eval_primary(expr, pos);
    skip_whitespace(expr, pos);

    while (pos < expr.size()) {
        char op = expr[pos];
        if (op != '*' && op != '/') break;
        pos++;
        double right = eval_primary(expr, pos);
        if (op == '*') left *= right;
        else {
            if (right == 0) throw runtime_error("Division by zero");
            left /= right;
        }
        skip_whitespace(expr, pos);
    }
    return left;
}

double eval_primary(const string& expr, size_t& pos) {
    skip_whitespace(expr, pos);
    if (pos >= expr.size()) {
        throw runtime_error("Unexpected end of expression");
    }

    if (expr[pos] == '(') {
        pos++;
        double value = eval_expression(expr, pos);
        skip_whitespace(expr, pos);
        if (pos >= expr.size() || expr[pos] != ')') {
            throw runtime_error("Missing closing parenthesis");
        }
        pos++;
        return value;
    }

    if (expr[pos] == '+' || expr[pos] == '-') {
        bool negative = (expr[pos] == '-');
        pos++;
        double value = eval_primary(expr, pos);
        return negative ? -value : value;
    }

    if (isdigit(expr[pos]) || expr[pos] == '.') {
        size_t start = pos;
        bool has_decimal = false;
        while (pos < expr.size() && (isdigit(expr[pos]) || expr[pos] == '.')) {
            if (expr[pos] == '.') {
                if (has_decimal) throw runtime_error("Invalid number format");
                has_decimal = true;
            }
            pos++;
        }
        return stod(expr.substr(start, pos - start));
    }

    throw runtime_error("Unexpected character: " + string(1, expr[pos]));
}

// 变量替换函数
string replace_variables(const string& expr) {
    regex var_re(R"(\b([a-zA-Z_]\w*)\b)");
    smatch match;
    string result;
    size_t last = 0;

    auto begin = expr.cbegin();
    while (regex_search(begin, expr.cend(), match, var_re)) {
        result += string(begin, begin + match.position());
        string var = match[1];
        if (!variables.count(var)) {
            throw runtime_error("Undefined variable: " + var);
        }
        result += to_string(variables[var]);
        begin += match.position() + match.length();
        last = begin - expr.begin();
    }
    result += expr.substr(last);
    return result;
}

// 处理单行输入
void process_line(const string& line) {
    try {
        string trimmed = line;
        trimmed.erase(remove_if(trimmed.begin(), trimmed.end(), ::isspace), trimmed.end());
        if (trimmed.empty()) return;

        // 处理赋值语句
        smatch match;
        regex assign_re(R"(^([a-zA-Z_]\w*)=(.*)$)");
        if (regex_match(trimmed, match, assign_re)) {
            string var = match[1];
            string expr = replace_variables(match[2]);
            variables[var] = evaluate(expr);
            cout << var << " = " << variables[var] << endl;
        }
        // 处理普通表达式
        else {
            string expr = replace_variables(trimmed);
            double result = evaluate(expr);
            cout << result << endl;
        }
    } catch (const exception& e) {
        cerr << "Error: " << e.what() << endl;
    }
}

int main() {
    cout << "Simple C++ Script Interpreter (type 'exit' to quit)" << endl;

    string line;
    while (true) {
        cout << "> ";
        getline(cin, line);
        if (line == "exit") break;
        process_line(line);
    }

    return 0;
}

step3:运行

C:\Users\wangrusheng\CLionProjects\untitled28\cmake-build-debug\untitled28.exe
Simple C++ Script Interpreter (type 'exit' to quit)
>a=5*3

a = 15
>b=a*2

b = 30
>c=5/0

>Error: Division by zero
a=9

a = 9
>8

8
>3/4*((2-(5/6))/(7/12)+(1/3)*(9/5)-(2/15))

1.85
>-2*2*((3/(-4)+0.5))-(((-5)*2-3)/7)

2.85714
>1/(1+(1/(2+(1/(3+(1/4))))))

0.697674
>2.5*((6-(3/2))*(6-(3/2)))/1.25-(5*5-(4*3))/(2*-1)

47
>

手动分割线:
step101:C:\Users\wangrusheng\CLionProjects\untitled28\main.cpp

#include <iostream>
#include <string>
#include <map>
#include <regex>
#include <cctype>
#include <vector>
#include <algorithm>
#include <sstream>
#include <stdexcept>
#include <fstream>  // 新增文件流支持

using namespace std;

map<string, double> variables;

// 辅助函数:跳过空白字符
void skip_whitespace(const string& expr, size_t& pos) {
    while (pos < expr.size() && isspace(expr[pos])) pos++;
}

// 表达式解析函数声明
double eval_expression(const string& expr, size_t& pos);
double eval_term(const string& expr, size_t& pos);
double eval_factor(const string& expr, size_t& pos);
double eval_primary(const string& expr, size_t& pos);

// 主解析函数
double evaluate(const string& expr) {
    size_t pos = 0;
    double result = eval_expression(expr, pos);
    skip_whitespace(expr, pos);
    if (pos != expr.size()) {
        throw runtime_error("Unexpected characters in expression");
    }
    return result;
}

// 表达式解析实现
double eval_expression(const string& expr, size_t& pos) {
    return eval_term(expr, pos);
}

double eval_term(const string& expr, size_t& pos) {
    double left = eval_factor(expr, pos);
    skip_whitespace(expr, pos);

    while (pos < expr.size()) {
        char op = expr[pos];
        if (op != '+' && op != '-') break;
        pos++;
        double right = eval_factor(expr, pos);
        if (op == '+') left += right;
        else left -= right;
        skip_whitespace(expr, pos);
    }
    return left;
}

double eval_factor(const string& expr, size_t& pos) {
    double left = eval_primary(expr, pos);
    skip_whitespace(expr, pos);

    while (pos < expr.size()) {
        char op = expr[pos];
        if (op != '*' && op != '/') break;
        pos++;
        double right = eval_primary(expr, pos);
        if (op == '*') left *= right;
        else {
            if (right == 0) throw runtime_error("Division by zero");
            left /= right;
        }
        skip_whitespace(expr, pos);
    }
    return left;
}

double eval_primary(const string& expr, size_t& pos) {
    skip_whitespace(expr, pos);
    if (pos >= expr.size()) {
        throw runtime_error("Unexpected end of expression");
    }

    if (expr[pos] == '(') {
        pos++;
        double value = eval_expression(expr, pos);
        skip_whitespace(expr, pos);
        if (pos >= expr.size() || expr[pos] != ')') {
            throw runtime_error("Missing closing parenthesis");
        }
        pos++;
        return value;
    }

    if (expr[pos] == '+' || expr[pos] == '-') {
        bool negative = (expr[pos] == '-');
        pos++;
        double value = eval_primary(expr, pos);
        return negative ? -value : value;
    }

    if (isdigit(expr[pos]) || expr[pos] == '.') {
        size_t start = pos;
        bool has_decimal = false;
        while (pos < expr.size() && (isdigit(expr[pos]) || expr[pos] == '.')) {
            if (expr[pos] == '.') {
                if (has_decimal) throw runtime_error("Invalid number format");
                has_decimal = true;
            }
            pos++;
        }
        return stod(expr.substr(start, pos - start));
    }

    throw runtime_error("Unexpected character: " + string(1, expr[pos]));
}

// 变量替换函数
string replace_variables(const string& expr) {
    regex var_re(R"(\b([a-zA-Z_]\w*)\b)");
    smatch match;
    string result;
    size_t last = 0;

    auto begin = expr.cbegin();
    while (regex_search(begin, expr.cend(), match, var_re)) {
        result += string(begin, begin + match.position());
        string var = match[1];
        if (!variables.count(var)) {
            throw runtime_error("Undefined variable: " + var);
        }
        result += to_string(variables[var]);
        begin += match.position() + match.length();
        last = begin - expr.begin();
    }
    result += expr.substr(last);
    return result;
}

// 处理单行输入
void process_line(const string& line) {
    try {
        string trimmed = line;
        trimmed.erase(remove_if(trimmed.begin(), trimmed.end(), ::isspace), trimmed.end());
        if (trimmed.empty()) return;

        // 处理赋值语句
        smatch match;
        regex assign_re(R"(^([a-zA-Z_]\w*)=(.*)$)");
        if (regex_match(trimmed, match, assign_re)) {
            string var = match[1];
            string expr = replace_variables(match[2]);
            variables[var] = evaluate(expr);
            cout << var << " = " << variables[var] << endl;
        }
        // 处理普通表达式
        else {
            string expr = replace_variables(trimmed);
            double result = evaluate(expr);
            cout << result << endl;
        }
    } catch (const exception& e) {
        cerr << "Error: " << e.what() << endl;
    }
}

int main() {
    // 设置默认文件路径(使用原始字符串避免转义)
    const string filepath = R"(C:\Users\wangrusheng\CLionProjects\untitled28\cmake-build-debug\input.txt)";

    // 打开输入文件
    ifstream input_file(filepath);

    if (!input_file.is_open()) {
        cerr << "Error: Could not open input file at:\n" << filepath << endl;
        return 1;
    }

    // 逐行读取并处理
    string line;
    while (getline(input_file, line)) {
        process_line(line);
    }

    input_file.close();
    return 0;
}

step102:C:\Users\wangrusheng\CLionProjects\untitled28\cmake-build-debug\input.txt

3/4*((2-(5/6))/(7/12)+(1/3)*(9/5)-(2/15))
-2*2*((3/(-4)+0.5))-(((-5)*2-3)/7)
1/(1+(1/(2+(1/(3+(1/4))))))

2.5*((6-(3/2))*(6-(3/2)))/1.25-(5*5-(4*3))/(2*-1)

step103:运行

C:\Users\wangrusheng\CLionProjects\untitled28\cmake-build-debug\untitled28.exe
1.85
2.85714
0.697674
47

Process finished with exit code 0

手动分割线
用python实现
step201:

import re

class Evaluator:
    def __init__(self):
        self.variables = {}

    def skip_whitespace(self, expr, pos):
        while pos[0] < len(expr) and expr[pos[0]].isspace():
            pos[0] += 1

    def eval_expression(self, expr, pos):
        return self.eval_term(expr, pos)

    def eval_term(self, expr, pos):
        left = self.eval_factor(expr, pos)
        self.skip_whitespace(expr, pos)

        while pos[0] < len(expr):
            op = expr[pos[0]]
            if op not in '+-':
                break
            pos[0] += 1
            right = self.eval_factor(expr, pos)
            if op == '+':
                left += right
            else:
                left -= right
            self.skip_whitespace(expr, pos)
        return left

    def eval_factor(self, expr, pos):
        left = self.eval_primary(expr, pos)
        self.skip_whitespace(expr, pos)

        while pos[0] < len(expr):
            op = expr[pos[0]]
            if op not in '*/':
                break
            pos[0] += 1
            right = self.eval_primary(expr, pos)
            if op == '*':
                left *= right
            else:
                if right == 0:
                    raise RuntimeError("Division by zero")
                left /= right
            self.skip_whitespace(expr, pos)
        return left

    def eval_primary(self, expr, pos):
        self.skip_whitespace(expr, pos)
        if pos[0] >= len(expr):
            raise RuntimeError("Unexpected end of expression")

        if expr[pos[0]] == '(':
            pos[0] += 1
            value = self.eval_expression(expr, pos)
            self.skip_whitespace(expr, pos)
            if pos[0] >= len(expr) or expr[pos[0]] != ')':
                raise RuntimeError("Missing closing parenthesis")
            pos[0] += 1
            return value

        if expr[pos[0]] in '+-':
            sign = -1 if expr[pos[0]] == '-' else 1
            pos[0] += 1
            primary = self.eval_primary(expr, pos)
            return sign * primary

        if expr[pos[0]].isdigit() or expr[pos[0]] == '.':
            start = pos[0]
            has_decimal = False
            while pos[0] < len(expr) and (expr[pos[0]].isdigit() or expr[pos[0]] == '.'):
                if expr[pos[0]] == '.':
                    if has_decimal:
                        raise RuntimeError("Invalid number format")
                    has_decimal = True
                pos[0] += 1
            num_str = expr[start:pos[0]]
            try:
                return float(num_str)
            except ValueError:
                raise RuntimeError(f"Invalid number: {num_str}")

        raise RuntimeError(f"Unexpected character: {expr[pos[0]]} at position {pos[0]}")

    def replace_variables(self, expr):
        def replacer(match):
            var_name = match.group(1)
            if var_name not in self.variables:
                raise RuntimeError(f"Undefined variable: {var_name}")
            return str(self.variables[var_name])
        try:
            replaced_expr = re.sub(r'\b([a-zA-Z_]\w*)\b', replacer, expr)
        except RuntimeError as e:
            raise e
        return replaced_expr

    def process_line(self, line):
        stripped = line.replace(' ', '')
        if not stripped:
            return
        try:
            match = re.fullmatch(r'^([a-zA-Z_]\w*)=(.*)$', stripped)
            if match:
                var = match.group(1)
                expr = match.group(2)
                replaced_expr = self.replace_variables(expr)
                pos = [0]
                value = self.eval_expression(replaced_expr, pos)
                if pos[0] != len(replaced_expr):
                    raise RuntimeError(f"Unexpected characters in expression: {replaced_expr[pos[0]:]}")
                self.variables[var] = value
                print(f"{var} = {value}")
            else:
                replaced_expr = self.replace_variables(stripped)
                pos = [0]
                value = self.eval_expression(replaced_expr, pos)
                if pos[0] != len(replaced_expr):
                    raise RuntimeError(f"Unexpected characters in expression: {replaced_expr[pos[0]:]}")
                print(value)
        except Exception as e:
            print(f"Error: {e}")

def main():
    evaluator = Evaluator()
    filepath = r'C:\Users\wangrusheng\CLionProjects\untitled28\cmake-build-debug\input.txt'
    try:
        with open(filepath, 'r') as f:
            for line in f:
                evaluator.process_line(line.strip())
    except IOError as e:
        print(f"Error opening file: {e}")

if __name__ == '__main__':
    main()

step202:运行

(.venv) PS C:\Users\wangrusheng\PycharmProjects\FastAPIProject1> python hello.py
1.8499999999999996
2.857142857142857
0.6976744186046512
47.0
a = 5.0
b = -7.0
c = -2.0
(.venv) PS C:\Users\wangrusheng\PycharmProjects\FastAPIProject1> 

end

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/2330250.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

青蛙吃虫--dp

1.dp数组有关元素--路长和次数 2.递推公式 3.遍历顺序--最终影响的是路长&#xff0c;在外面 其次次数遍历&#xff0c;即这次路长所有情况都更新 最后&#xff0c;遍历次数自然就要遍历跳长 4.max时时更新 dp版本 #include<bits/stdc.h> using namespace std; #def…

LINUX 5 cat du head tail wc 计算机拓扑结构 计算机网络 服务器 计算机硬件

计算机网络 计算机拓扑结构 计算机按性能指标分&#xff1a;巨型机、大型机、小型机、微型机。大型机、小型机安全稳定&#xff0c;小型机用于邮件服务器 Unix系统。按用途分&#xff1a;专用机、通用机 计算机网络&#xff1a;局域网‘、广域网 通信协议’ 计算机终端、客户端…

ModuleNotFoundError: No module named ‘pandas‘

在使用Python绘制散点图表的时候&#xff0c;运行程序报错&#xff0c;如图&#xff1a; 报错显示Python 环境中可能没有安装 pandas 库&#xff0c;执行pip list命令查看&#xff0c;果然没有安装pandas 库&#xff0c;如图&#xff1a; 执行命令&#xff1a;python -m pip in…

【教程】MacBook 安装 VSCode 并连接远程服务器

目录 需求步骤问题处理 需求 在 Mac 上安装 VSCode&#xff0c;并连接跳板机和服务器。 步骤 Step1&#xff1a;从VSCode官网&#xff08;https://code.visualstudio.com/download&#xff09;下载安装包&#xff1a; Step2&#xff1a;下载完成之后&#xff0c;直接双击就能…

Unet网络的Pytorch实现和matlab实现

文章目录 一、Unet网络简介1.1 输入图像1.2 编码器部分&#xff08;Contracting Path&#xff09;1.3 解码器部分&#xff08;Expanding Path&#xff09;1.4 最后一层&#xff08;输出&#xff09;1.5 跳跃连接&#xff08;Skip Connections&#xff09; 二、Unet网络的Pytorc…

【合新通信】相控阵雷达RFoF方案的应用

一、相控阵雷达为何需要RFoF&#xff1f; 核心需求驱动 分布式部署&#xff1a;相控阵雷达&#xff08;AESA/PESA&#xff09;的T/R模块需分散布局&#xff08;如舰载雷达阵面、卫星载荷&#xff09;&#xff0c;传统同轴电缆导致重量和损耗剧增。高频段挑战&#xff1a;X/Ku/…

原理图输出网表及调入

一、输出网表操作步骤 &#xff08;1&#xff09;选中.dsn文件&#xff0c;选者N或进入tools下拉列表选择Creat Netlists &#xff08;2&#xff09;导出网表后的文件 二、网表的导入 &#xff08;1&#xff09;执行菜单命令“File-Import-Logic/netlist”&#xff0c;将原理…

TDengine JAVA 语言连接器

简介 本节简介 TDengine 最重要且使用最多的连接器, 本节内容是以教科书式方式列出对外提供的接口及功能及使用过程中要注意的技术细节&#xff0c;大家可以收藏起来做为今后开发 TDengine 的参考资料。 taos-jdbcdriver 是 TDengine 的官方 Java 语言连接器&#xff0c;Java…

【NLP 55、实践 ⑬ LoRA完成NER任务】

目录 一、数据文件 二、模型配置文件 config.py 三、数据加载文件 loader.py 1.导入文件和类的定义 2.初始化 3.数据加载方法 代码运行流程 4.文本编码 / 解码方法    ① encode_sentence()&#xff1a; ② decode()&#xff1a; 代码运行流程 ③ padding()&#xff1a; 代码…

【蓝桥杯】Python大学A组第十五届省赛

1.填空题 1.1.拼正方形 问题描述 小蓝正在玩拼图游戏,他有个的方块和个的方块,他需要从中挑出一些来拼出一个正方形。 比如用个和个的方块可以拼出一个的正方形;用个的方块可以拼出一个的正方形。 请问小蓝能拼成的最大的正方形的边长为多少。 import math # 2*2的个数 a =…

小球反弹(蓝桥杯C语言)

有一长方形&#xff0c;长为 343720343720 单位长度&#xff0c;宽为 233333233333 单位长度。在其内部左上角顶点有一小球 (无视其体积)&#xff0c;其初速度如图所示且保持运动速率不变&#xff0c;分解到长宽两个方向上的速率之比为 dx:dy15:17dx:dy15:17。小球碰到长方形的…

HarmonyOS-ArkUI Ability进阶系列-UIAbility与各类Context

UIAbility及相关类关系 一个模块编译的时候会出一个HAP包&#xff0c; 每一个HAP包在运行时都对应一个AbilityStage。 AbilityStage持有一个AbilityStageContext一个APP&#xff0c; 有时候会有很多个HAP包&#xff0c; 至少一个。 一个APP运行时&#xff0c;对应的是我们的App…

剑指Offer(数据结构与算法面试题精讲)C++版——day4

剑指Offer&#xff08;数据结构与算法面试题精讲&#xff09;C版——day4 题目一&#xff1a;和为k的子数组题目二&#xff1a;0和1个数相同的子数组题目三&#xff1a;左右两边子数组的和相等 题目一&#xff1a;和为k的子数组 结合前面着重阐述的双指针法这一经典的算法技巧&…

WebRTC技术简介及应用场景

写在前面 本文是参考稀土掘金的文章,整理得出,版权归原作者所有!参考链接请点击跳转 WebRTC&#xff08;Web Real-Time Communication&#xff09; 是一项开源技术&#xff0c;允许浏览器和移动应用直接进行实时音视频通信和数据传输&#xff0c;无需安装插件或第三方软件。它…

介绍几种创意登录页(含完整源码)

今天为大家收集了几种不同风格的登录页&#xff0c;搭配动态渐变背景&#xff0c;效果绝对惊艳&#xff01; CSS3实现动态渐变玻璃拟态登录页 一、开篇语 纯CSS实现当下最火的玻璃拟态(Morphism)风格登录页&#xff0c;搭配动态渐变背景&#xff0c;效果绝对惊艳&#xff01; …

Uni-app入门到精通:uni-app的基础组件

1、view view是容器组件&#xff0c;类似于HTML中的<div></div>标签&#xff0c;用于包裹各种元素内容&#xff0c;是页面布局常用的组件。view组件的属性如下 属性类型默认值说明hover-classStringnone指定按下去的样式类。当hover-class"none"时&…

大文件上传源码,支持单个大文件与多个大文件

大文件上传源码&#xff0c;支持单个大文件与多个大文件 Ⅰ 思路Ⅱ 具体代码前端--单个大文件前端--多个大文件前端接口后端 Ⅰ 思路 具体思路请参考我之前的文章&#xff0c;这里分享的是上传流程与源码 https://blog.csdn.net/sugerfle/article/details/130829022 Ⅱ 具体代码…

C语言--插入排序

插入排序&#xff1a;简单而高效的排序算法 在计算机科学中&#xff0c;排序是一种常见的操作&#xff0c;用于将一组数据按照特定的顺序排列。插入排序&#xff08;Insertion Sort&#xff09;是一种简单直观的排序算法&#xff0c;它的工作原理类似于我们整理扑克牌的过程。…

L2-024 部落 #GPLT,并查集 C++

文章目录 题目解读输入格式输出格式 思路Ac Code参考 题目解读 我们认为朋友的朋友都算在一个部落里&#xff0c;于是要请你统计一下&#xff0c;在一个给定社区中&#xff0c;到底有多少个互不相交的部落&#xff1f;并且检查任意两个人是否属于同一个部落。 输入格式 第一…

在线记事本——支持Markdown

项目地址 https://github.com/Anyuersuper/CloudNotebook 百度网盘 通过网盘分享的文件&#xff1a;CloudNotebook-master.zip 链接: https://pan.baidu.com/s/1_Y--aBzNkKiFRIMHYmwPdA?pwdyuer 提取码: yuer &#x1f4dd; 云笔记 (Cloud Notebook) 云笔记是一个简洁、安全…