自定义博客皮肤VIP专享

*博客头图:

格式为PNG、JPG,宽度*高度大于1920*100像素,不超过2MB,主视觉建议放在右侧,请参照线上博客头图

请上传大于1920*100像素的图片!

博客底图:

图片格式为PNG、JPG,不超过1MB,可上下左右平铺至整个背景

栏目图:

图片格式为PNG、JPG,图片宽度*高度为300*38像素,不超过0.5MB

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+
  • 博客(153)
  • 收藏
  • 关注

原创 027.打印蛇形方阵

#include<stdio.h>#define N 20int main(){ int i, j, a[N][N], n, k; printf("请输入矩阵的阶:\n"); scanf_s("%d",&n); k = 1; /*输出上三角*/ for (i = 1; i <= n; i++) { for (j = 1; j <= i; j+...

2020-04-30 20:59:38 211

原创 031.Ada语言中更进一步自定义类型实例

-- Chapter 7 - Program 3with Ada.Text_IO;use Ada.Text_IO;procedure MoreDers is -- Some floating point types type NEW...

2020-04-30 20:37:26 137

原创 030.派生类型的子类型的定义和使用以及子类型的派生类型的示例

with Ada.Text_IO,Ada.Integer_Text_IO;use Ada.Text_IO,Ada.Integer_Text_IO;procedure DerSubs is type NEW_INT is new Integer range 12..127; type NEW_INT_TYPE is new Integer; subtype S...

2020-04-30 20:27:51 112

原创 029.用户自定义类型以及派生类型

如果没有程序员明确说明的正确类型转换,这些类型的变量就不能以任何方式混合with Ada.Text_IO,Ada.Integer_Text_IO;use Ada.Text_IO,Ada.Integer_Text_IO;procedure DerTypes is type LITTLE_INT is range -24..17; type TINY_INT is rang...

2020-04-30 19:11:08 121

原创 026.穷举法验证哥德巴赫猜想:任一大于6的数字都可以被拆分为两个素数之和

#include<iostream> using namespace std;int isPrime(int n) { //判断是否是素数 int i; if (n == 1) return 1; else { for (i = 2; i < n; i++) if (n % i == 0) return 0; return 1; }}i...

2020-04-30 18:34:26 474

原创 025.打印螺旋矩阵

#include<iostream>#define N 10using namespace std;int main(){ int Matrix[N][N]; int k = 1; cout << "Spiral Matrix:" << endl; for (int i = 0; i <= N / 2; i++)//控制圈数 {...

2020-04-30 18:00:12 96

原创 LeetCode:137. 只出现一次的数字 II(纯数学解法)

思路,首先将所有的数字去重加起来*3,然后再减去原来的集合去重后的和,得到的就是二倍的只出现一次的那个数字,返回结果的二分之一即可。class Solution: def singleNumber(self, nums: List[int]) -> int: return (sum(set(nums))*3-sum(nums))//2;...

2020-04-30 16:06:57 163

原创 LeetCode:119.杨辉三角II

class Solution {public: vector<vector<int>> generate(int numRows) { vector<vector<int>>res; for(int i=0;i<numRows;i++) { vector&...

2020-04-30 15:15:21 81

原创 LeetCode:118.杨辉三角

class Solution {public: vector<vector<int>> generate(int numRows) { vector<vector<int>>res; for(int i=0;i<numRows;i++) { vector<i...

2020-04-30 15:09:08 52

原创 LeetCode:202.快乐数

class Solution {public: int count(int n) { int sum=0; while(n) { sum+=(n%10)*(n%10); n/=10; } return sum; } set<int&...

2020-04-30 13:07:49 147

原创 LeetCode:204.计数质数

class Solution { public int countPrimes(int n) { int count = 0; for (int i = 1; i < n; i++) { if (isPrime(i)) count++; } return count; } private boolean isPrime...

2020-04-30 12:24:53 90

原创 028.混合不同的类型

with Ada.Text_IO;use Ada.Text_IO;procedure MixTypes is PI : constant := 3.1416; TWO_PI : constant := 2 * PI; type MY_FLOAT is digits 7; Size : MY_FLOAT; type MY_FIXED is delta 0.1...

2020-04-29 20:53:00 70

原创 027.Ada语言中的decimal type

with Ada.Text_IO;use Ada.Text_IO;procedure Decimal is type DOLLAR is delta 0.01 digits 8 range 0.00..1_000.00; type DIMES is delta 0.1 digits 6; Amount : DOLLAR := 3.00; Coins : DIM...

2020-04-29 19:25:18 133

原创 026.Ada语言的定点类型

with Ada.Text_IO;use Ada.Text_IO;procedure Fixed is COARSE_PI : constant :=3.15; type MY_FIXED is delta 0.1 range -40.0..120.0; type ANGLE is delta 0.05 range -COARSE_PI..COARSE_PI...

2020-04-29 19:20:59 128

原创 025.Ada的浮点类型变量

with Ada.Text_IO;use Ada.Text_IO;procedure FloatVar is PI : constant :=3.1416; TWO_PI:constant :=2*PI; R : Float; type MY_FLOAT is digits 7; type MY_LONG_FLOAT is digits ...

2020-04-29 18:57:20 114

原创 024.Ada的模块化类型变量

with Ada.Text_IO;use Ada.Text_IO;procedure Modular is type DIAL_RANGE is mod 5; Dial :DIAL_RANGE:=3; type MY_BINARY_BIT is mod 2; My_Bit :MY_BINARY_BIT:=1; type MY_UNSIGN...

2020-04-29 18:27:46 95

原创 023.Ada语言的整数类型中的不是很有用的属性

with Ada.Text_IO;use Ada.Text_IO;procedure IncrInt is Index : Integer; begin Index:=13; Index:=Integer'Pos(Index); -- Still 13 Index:=Integer'Val(Index); -- Still 13 Inde...

2020-04-29 18:10:19 93

原创 022.使用布尔变量

with Ada.Text_IO;use Ada.Text_IO;procedure BoolVars is package Bool_IO is new Ada.Text_IO.Enumeration_IO(Boolean); use Bool_IO; Correct :Boolean; Maybe :Boolean; Probably:B...

2020-04-29 18:04:24 125

原创 024.Karatsuba算法

#include<iostream>#include<cmath>#include<algorithm>using namespace std;//计算某一运算数的位数int size(long long x){ int sum = 0; do { sum++; x /= 10; } while (x); return su...

2020-04-29 14:55:19 714

原创 LeetCode:1103.分糖果II

class Solution {public: vector<int> distributeCandies(int candies, int num_people) { int people=1; int n=0; int distribute=1; vector<int>res(num_people...

2020-04-29 13:19:13 89

原创 LeetCode:1089.复写零

class Solution {public: void duplicateZeros(vector<int>& arr) { //首先进行复写操作 int mottoSum=arr.size();//记录原来数组的大小 int i=0; while(i<arr.size()-1) ...

2020-04-29 12:56:34 113

原创 LeetCode:88. 合并两个有序数组

class Solution {public: void merge(vector<int>& nums1, int m, vector<int>& nums2, int n) { //将nums1的前m号元素以及nums2的前n号元素取出来 vector<int>n1,n2; i...

2020-04-29 12:17:51 59

原创 LeetCode:101.对称二叉树

    这道题是吉林大学2020年研究生入学考试计算机学院专硕966的一道15大题,题目也是采用递归的方式求解。他的思路比较简单,简单来说就是再次"复制"一颗同样的二叉树(也就是isSame里面传了两次root参数)通过条件判断,人为地将其中一棵二叉树进行所谓的"镜像"操作,进而判断是否对称。/** * Definition for a binary t...

2020-04-29 11:36:51 79

原创 LeetCode:100. 相同的树

/** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x) : val(x), left(NULL), right(NULL) {} * }; */clas...

2020-04-29 11:09:28 54

原创 023.利用递归求解斐波那契数列第n项

#include<iostream>using namespace std;long fib(long n){ if (n == 0 || n == 1) { return n; } else { return fib(n - 1) + fib(n - 2); }}int main(){ while (true) { int n; cout...

2020-04-28 22:21:20 362

原创 Chapter01.06::为图像添加水平或者垂直参考线

import matplotlib.pyplot as pltimport numpy as npx=np.linspace(0.05,10,1000)y=np.sin(x)plt.plot(x,y,ls="-",lw=2,c="c",label="plot figure")plt.legend()plt.axhline(y=0.0,c="r",ls="--",lw=2)pl...

2020-04-28 21:38:31 294

原创 Chapter01.05::使用grid函数为图像添加网格参考线

import matplotlib.pyplot as pltimport numpy as npx=np.linspace(0.05,10,1000)y=np.sin(x)plt.plot(x,y,ls="-",lw=2,c="c",label="plot figure")plt.legend()plt.grid(linestyle=":",color="r")plt.s...

2020-04-28 21:37:09 243

原创 Chapter01.04::在坐标轴上添加标记信息

import matplotlib.pyplot as pltimport numpy as npx=np.linspace(0.05,10,1000)y=np.sin(x)plt.plot(x,y,ls="-.",lw=2,c='c',label="plot figure")plt.legend()plt.xlabel("x-axis")plt.ylabel("y-axis...

2020-04-28 21:35:14 111

原创 Chapter01.03::使用xlim显示X轴坐标的范围

import matplotlib.pyplot as pltimport numpy as npx=np.linspace(0.05,10,1000)y=np.random.rand(1000)plt.scatter(x,y,label="scatter figure")plt.legend()plt.xlim(0.05,10)plt.ylim(0,1)plt.show...

2020-04-28 21:34:10 151

原创 Chapter01.02::使用scatter绘制散点图

import matplotlib.pyplot as pltimport numpy as npx=np.linspace(0.05,10,1000)y=np.random.rand(1000)plt.scatter(x,y,label="scatter figure")plt.legend()plt.xlim(0.05,10)plt.ylim(0,1)plt.show()...

2020-04-28 21:33:07 123

原创 Chapter01.01::利用plot()函数绘制余弦函数图像

import matplotlib.pyplot as pltimport numpy as npx=np.linspace(0.05,10,1000)y=np.cos(x)plt.plot(x,y,ls="-",lw=2,label="plot figure")plt.legend()plt.show()

2020-04-28 21:31:46 389

原创 022.欧几里得算法

#include<iostream>using namespace std;int gcd(int m, int n){ int r; h: r = m - floor(m / n) * n; if (r == 0) { return n; } else { m = n; n = r; goto h; }}int main(){ ...

2020-04-28 21:19:44 83

原创 021.计算阶乘(递归算法)

#include<iostream>using namespace std;int factorial(int n){ if (n == 0) { return 1; } else { return n * factorial(n - 1); }}int main(){ int result = factorial(10); cout <...

2020-04-28 21:17:36 103

原创 008.利用深度优先搜索,判断两个节点是否连通,并且返回他们之间的路径

import java.util.ArrayList;import java.util.Collections;public class SingleSourcePath { private Graph G; private int s; private boolean [] visited; private int [] pre; public SingleSource...

2020-04-28 21:00:28 1247

原创 007.求解连通分量,以及判断两个节点是否处于同一个图中

       下面的代码是基于java语言的求解连通分量的具体代码实现,其功能包含求解连通分量的个数,输出每一个连通分量的节点。判断两个节点是否处于同一个连通分量之中。import java.util.ArrayList;public class ConnectedComponent { private Graph G; private int ...

2020-04-28 20:22:56 739

原创 020.自定义排序规则对结构体数组进行排序(以学生信息为例)

#include<iostream>#include<cstring>#include<algorithm>using namespace std;typedef struct Student{ char id[15];//15位学号 int score;//某科课程分数}stu;//定义排序规则bool cmp(Student a, ...

2020-04-28 19:19:12 313

原创 019.使用递归求解汉诺塔问题

#include<iostream>using namespace std;void move(char a, char b){ cout << a<<"----------------->" << b << endl;}void hanoi(int n, char a, char b,char c)//将n个盘子由...

2020-04-28 19:16:19 137

原创 018.矩阵的运算

      下面这段程序给出了矩阵的加法,减法,以及乘法的运算,并且使用了运算符重载等方式输出求解的答案,欲了解详细的过程请认真阅读代码。#include<iostream>using namespace std;template<typename T>class Matrix{private: ...

2020-04-28 19:09:31 137

原创 018.Red-Black Tree

     这里给出一种平衡二叉搜索树红黑树的实现,代码参考并整理自清华大学邓俊辉《数据结构C++版》。红黑树(英语:Red–black tree)是一种自平衡二叉查找树,是在计算机科学中用到的一种数据结构,典型的用途是实现关联数组。它在1972年由鲁道夫·贝尔发明,被称为"对称二叉B树",它现代的名字源于Leo J. Guibas和Robert...

2020-04-28 18:05:50 251

原创 021.枚举类型

with Ada.Text_IO;use Ada.Text_IO;procedure Enum is type DAY is (MON,TUE,WED,THU,FRI,SAT,SUN); subtype WORK_DAY is DAY range MON..FRI; subtype PLAY_DAY is DAY range SAT..SUN; typ...

2020-04-28 16:51:51 77

空空如也

空空如也

TA创建的收藏夹 TA关注的收藏夹

TA关注的人

提示
确定要删除当前文章?
取消 删除