➔ 【Cpp】assert_断言
| 1 minute read
assert_断言 // Assert : 断言 // // See more info: // <a herf= "https://baike.baidu.com/item/assert/10931289?fr=aladdin">assert</a> // // For developer not for user // // 定义 NDEBUG 编译器会移除所有的 assert() 代码 // #define NDEBUG #include <iostream> // #include <assert.h> #include <cassert> void foo(int i){ // i > 0; 如果 i > 0 为假,则立即终止程序 // 注意: 这里程序终止是因为我们自己的代码出现问题,和用户无关 // 字符串在 c/c++ 中是地址,不会为 0, 永远不会为 false. // 所以可以用来 做一些标识 assert(i > 0 && i < 600 && "你好啊,这里是一个 assert,可以在这里添加note"); std::cout<< "i = " << i << ", The parameter value is ok !
Read More >>
➔ 【编程题】找出二进制数组中连续1的最大长度
| 1 minute read
【编程题】找出二进制数组中连续1的最大长度 Max Consecutive(连续的) Ones Given a binary array nums, return the maximum number of consecutive 1’s in the array. Example 1:
Input: nums = [1,1,0,1,1,1] Output: 3 Explanation: The first two digits or the last three digits are consecutive 1s. The maximum number of consecutive 1s is 3. Example 2:
Input: nums = [1,0,1,1,0,1] Output: 2 #include <iostream> #include <vector> using namespace std; int findMaxConsecutiveOnes(vector<int>& nums) { int count = 0; int max_num = 0; for(int i = 0; i < nums.
Read More >>
➔ 【C】什么是typedef
| 2 minute read
【C】什么是typedef 什么是 typedef ? typedef is a keyword used in C language to assign alternative names to existing datatypes . Its mostly used with user defined datatypes, when names of the datatypes become slightly complicated to use in programs. typedef 是 C 语言中的关键字,给 现有的 数据类型 自定义一个名字, 通常用于用户自定义数据类型, 当 程序的数据类型变得复杂的时候,可以使 code 更简洁 #include <stdio.h> #include <stdlib.h> // you can give it another name to a datatype // your code define your own datatype name // // Example: typedef struct Point{ double x,y; } Point; // 或者 typedef struct Point Point int main(int argc, char *argv){ Point p; p.
Read More >>
➔ 【GDB】错误Undefined
| 1 minute read
Undefined command: “layout”. Try “help”. 在使用 GDB 调试时出现如下报错 $ gdb hello GNU gdb (Debian 10.1-2) 10.1.90.20210103-git Copyright (C) 2021 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html> This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law. Type "show copying" and "show warranty" for details. This GDB was configured as "x86_64-linux-gnu". Type "show configuration" for configuration details.
Read More >>
➔ 【编程题】指针操作内存实现整数相加减
| 2 minute read
Problem A Pointer in C++ is used to share a memory address among different contexts (primarily functions).
They are used whenever a function needs to modify the content of a variable, but it does not have ownership.
In order to access the memory address of a variable, *val*, prepend it with *&* sign.
For example, &val returns the memory address of *val*.
This memory address is assigned to a pointer and can be shared among functions.
Read More >>
➔ 【VUE】Vuetify安装报错问题
| 1 minute read
在安装 vuetify 时 报错 ERROR Error: You cannot call "get" on a collection with no paths. Instead, check the "length" property first to verify at least 1 path exists. 解决方案 打开main.js 文件
默认里面是
import { createApp } from "vue"; import App from "./App.vue"; createApp(App).mount("#app"); 替换为
import Vue from "vue"; import App from "./App.vue"; import vuetify from "./plugins/vuetify"; new Vue({ vuetify, render: (h) => h(App), }).$mount("#app"); 报错原因 因为当前 Vue 3.
Read More >>
➔ Voice_test
| 1 minute read
this the test page of testing if the voice can work here
➔ 图形化_if_else_if_声明
| 2 minute read
图形化_if_else_if_声明 在写条件语句时,有时候会将 if if…else if 搞 混,其实 根据 英语语义可以很明确的去理解 C++ 中的 if … else if #include<iostream> using namespace std; int main() { // Declare and initalize variables int a = 4; int b = 1; // if statement if (a == 5) { cout << "Inside if statement (a == " << a << ")" << endl; } // if and else statement // if 后面的表达式 为真 时 // 执行 if 后 花括号的内容 // else if 也是 // 只有 if 和 之后 的 else if 都为假的时候 // 才执行 else 的 内容 if(a > 5 ) { cout << "a > 5 (within if else statement)" <<endl; } else if(b == 10) { cout << "b == 10 (within else if )" <<endl; } else{ cout << " any other case" << endl; } // switch statement switch (a){ case 4 : cout << a << " == 4 (within case 4)" << endl; break; case 6 : cout << a << " == 5 (within case 6)" << endl; break; default: cout << a << " == 5 (within case 6)" << endl; } return 0; } Java 中的 if … else if package com.
Read More >>
➔ 【JAVA】随机数范围的抽象
| 1 minute read
将 JAVA 的 Random 范围抽象出来,从而只用考虑随机数的 开始点 和 结束点 package com.company; // 导入 Random 类 import java.util.Random; public class Random_numbers { public static void main(String[] args) { // 创建 random 实例 Random random = new Random(); // 1. 在 int 数据类型 内的随机数 int x = random.nextInt(); System.out.println(x); // 2. 设置获得的随机数的范围 // 注意:是从 0 到 '你设置的边界'(可达到的最大数,不包括边界数) // 因为计算机总是从 0 开始计数 int y = random.nextInt(10); System.out.println(y); // 3. 获取 5 ~ 15 之间的随机数 // 最初的范围是 0 ~ 10 , 都加上 5 之后 // 范围变成 5 ~ 15 int z = random.
Read More >>
➔ 【Cpp】容器
| 3 minute read
C++ 中的容器 // This Program show off sequential container in the C++ Standard library // C++ 中的容器 #include <iostream> #include <vector> #include <list> #include <forward_list> #include <string> #include <array> #include <deque> #include <algorithm> using namespace std; template <typename T> void print_container(T a){ for(auto i : a){ cout << i << " "; }; cout << endl; } int main(){ // Arrays are fixed-sized containers // 数组是固定大小的 // Specify a type and size // 特别说明 数组的大小和数据类型 // Has fast random access array<int, 10> int_array = {9,4,3,8,7,0,9,7,4,6}; // Print the array, sort it, and print again // 打印出数组,使用 算法库中的 sort 排序 之后在打印出来 cout << "Array: " << endl; print_container(int_array); // 将数字从小到大排列 sort(int_array.
Read More >>