- 博客(26)
- 问答 (1)
- 收藏
- 关注
原创 使用lambda表达式分别获取并输入形参
#include #include using namespace std;auto Pair = [](auto u, auto v) {return [=](auto f) {return f(u, v);};};auto First = [](auto p){auto temp = [](auto u, auto v) {return u;};return p(temp);};auto Second= [=](auto p){auto temp = [](auto u, au
2021-12-23 23:05:14
740
原创 c++运算符重载
实现左移和递增运算符重载#include <iostream>using namespace std;class MyInteger{ friend ostream& operator<<(ostream& cout, MyInteger myInt);public: MyInteger(int value) { this->m_Num = value; } MyInteger& operator++() { ++m_Nu
2021-02-15 12:45:41
174
原创 c++ primier练习9.4
#include <iostream>#include <vector>using namespace std;using std::vector;bool findNumber(vector<int>::iterator begin, vector<int>::iterator end, int target){ while (begin != end) { if ((*begin) == target) { return true
2021-01-31 13:42:56
209
原创 C++冒泡排序
#include <iostream>using namespace std;void bubbleSort(int * arr,int len){ for (int i = 0; i < len - 1; ++i) { for (int j = 0; j < len - i - 1; ++j) { if (arr[j] > arr[j + 1]) { int temp = arr[j]; arr[j] = arr[j + 1]
2021-01-22 23:20:10
109
原创 C++分离式编译
在.h文件中进行函数声明:#ifndef CHAPTER6_H#define CHAPTER6_H int fact(int);#endif在fact.cc中进行函数定义:#include "Chapter6.h" int fact(int val){ if (val == 0) return 1; else return val * fact(val - 1);}在程序中调用函数:#include "Chapter6.h"#include &l
2020-12-20 10:23:58
225
1
原创 c++Primer3.24练习
#include <iostream>#include <string>#include <vector>using std::string;using std::vector;using std::cout;using std::cin;using std::endl;int main() { vector<int> v1; int number; while (cin >> number) v1.push_bac
2020-11-30 13:29:46
180
原创 c++ primer 第五版 练习3.23
#include <iostream>#include <string>#include <vector>using std::string;using std::vector;using std::cout;using std::cin;using std::endl;int main() { vector<int> v1 = { 1,2,3,4,5,6,7,8,9,10 }; for (auto it = v1.begin();
2020-11-30 11:38:47
157
原创 初识c++字符串对象string
#include <iostream>#include <string>using std::cout;using std::cin;using std::endl;using std::string;int main(){ string s1, s2; cin >> s1 >> s2; cout << s1 << s2 << endl; string word; while (cin >
2020-11-29 11:00:44
143
原创 JS实现简单的图片轮播
let pic = ['bucks.jpg','dallas.jpg','heat.jpg','kings.jpg','lakers.jpg','nets.jpg','pistons.jpg','spurs.jpg'] let num = 0 let timer = setInterval(function (){ if (num < ...
2020-05-08 14:40:21
133
原创 利用复合梯形法则求定积分
复合梯形法则通过把区间[a,b]分成子区间,并在每个子区间用梯形法则近似积分得到的。利用 MATLAB近似取不同间隔h,观察值的变化。代码如下:
2019-12-21 14:01:58
2867
1
原创 插值多项式的拉格朗日形式
年份(1900年以后):0 20 40 60 80 100人口(百万):76.0 105.7 131.7 179.3 226.5 281.4利用MATLAB把1900年之后的年份输入到向量x,把相应的人口输入到向量y,并给出指令plot(x,y,‘o’),求通过每个数据点的5次多项式。基于拉格朗日的多项式插值公式:functi...
2019-12-17 16:03:37
575
1
原创 matlab------二分法求一元非线性方程的解
function [n,an,bn,rn,f]=half(a,b,tol)n=0;rn=NaN;f=NaN;ya=fun(a);yb=fun(b);an=a;bn=b;fprintf('------------------------------------------------------------\n')fprintf(' n an bn ...
2019-11-26 14:32:34
731
原创 matlab实现双骰子游戏
写一个蒙特卡罗模拟判定双骰子游戏获胜几率,function f=double_shai()times=zeros(1,2);n=100000;for i=1:n num1=fix(6*rand)+1; num2=fix(6*rand)+1; sumtwo1=num1+num2; if (sumtwo1 == 7 || sumtwo1 == 11) ...
2019-11-20 13:52:15
3425
原创 matalab-----蒙特卡洛方法模拟蒙提霍尔问题
利用matlab,写一个蒙特卡洛模拟验证蒙提霍尔概率问题:function f = mentihuoer()win_times=zeros(1,2);car_box_id=fix(3*rand)+1;n=100000;for i=1:n chose_id=fix(3*rand)+1; if chose_id == car_box_id win_times(...
2019-11-20 10:30:54
725
原创 python创建选课系统-----02.实现管理员视图
管理视图:创建讲师, 创建班级,创建课程,详情请见代码:from school_system import *catalogue = { '1': 'create_teacher', '2': 'create_class', '3': 'create_course',}def create_teacher(school): id_num = input...
2019-09-12 11:14:39
233
原创 python创建选课系统-----01.实现学校、课程、学生及班级角色创建
首先实现各个角色的创建,同时将各角色的相关联属性连系起来,详细请看代码:#后期保存合格对象的数据集合school_list = []course_list = {}class_list = {}teacher_list = {}student_list = []class School(object): """ 创建学校 """ def __in...
2019-09-11 11:09:27
1187
原创 python 实现计算器功能
开发一个简单的python计算器实现加减乘除及拓号优先级解析用户输入 1 - 2 * ( (60-30 +(-40/5) * (9-25/3 + 7 /399/42998 +10 * 568/14 )) - (-43)/ (16-32) )等类似公式后,必须自己解析里面的(),+,-,,/符号和公式(不能调用eval等类似功能偷懒实现),运算后得出结果,结果必须与真实的计算器所得出的结果一致...
2019-09-03 22:56:39
598
原创 python实现添加商品至购物车
利用python简单实现选择商品列表里的商品,并添加至购物车,计算总价格:def shopping(): global shopping_list print('shopping_list is showing:') for i in range(len(shopping_list)): key = str(i + 1) print(key...
2019-08-19 15:15:32
2361
原创 python实现注册登录
利用python实现简单的注册登录:#注册import jsondef register(): with open('user_db.json', 'r', encoding='utf-8')as f: user_data = json.load(f) user_list = {} print('please register new user')...
2019-08-19 13:51:40
670
原创 python之lintcode刷题: Reverse Words in a String
Reverse Words in a StringGiven an input string, reverse the string word by wordclass Solution: """ @param: s: A string @return: A string """ def reverseWords(self, s): ...
2019-08-09 21:34:20
268
原创 python之lintcode刷题: Unique Characters
Unique CharactersImplement an algorithm to determine if a string has all unique characters.def isUnique(str): # write your code here for i in range(len(str)): for j in range(i + 1,...
2019-08-09 21:20:10
257
原创 python之lintcode刷题:Find The Numbers II
Given two numbers A and B, find out all the numbers which are the multiple of 3 between A and B (including A and B). Return the sum of these numbers.代码:def getSum(A, B): # Write your code here ...
2019-08-05 22:44:55
290
原创 python之lintcode刷题:single number
Single NumberGiven 2 * n + 1 numbers, every numbers occurs twice except one, find it.ExampleExample 1:Input:[1,1,2,2,3,4,4]Output:3Explanation:Only 3 appears onceExample 2:Input:[0,0,1]Outpu...
2019-08-05 21:19:55
163
原创 python之lintcode刷题:Narcissistic number
def su_mu(n): num_list = [] if n == 1: for demo in range(10 ** n): sum = 0 for i in range(1, n + 1): sum += int(str(demo)[i - 1]) ** n ...
2019-08-04 15:35:39
277
原创 python之lintcode刷题:two sun
给一个整数数组,找到两个数使得他们的和等于一个给定的数 target。你需要实现的函数twoSum需要返回这两个数的下标, 并且第一个下标小于第二个下标。注意这里下标的范围是 0 到 n-1。def twoSum(self, numbers, target): # write your code here for i in range(len(numbers))...
2019-08-04 14:15:11
165
原创 python之lintcode刷题:rotate string
def rotateString(s, offset): # write your code here str_length = len(s) str_new = s[str_length - offset:] + s[:str_length - offset] return str_newstr_old = 'abcdefgh'print(rotateSt...
2019-08-04 13:37:18
208
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人