//计算器Ⅰ
class Solution {
public:
int calculate(string s) {
int len = s.size();//字符串长度
stack<int> temp;//暂放结果和状态
int result = 0, op = 1;
for (int i = 0; i < len; i++) {
if (s[i] == ' ')
continue;
if (s[i] == '(') {
temp.push(result);//将结果入栈
temp.push(op);//将状态入栈
result = 0;
op = 1;
}
else if (s[i] == ')') {
op = temp.top();//取出上次状态
temp.pop();
int t_result = temp.top();
temp.pop();
result = t_result + op * result;
}
else if (s[i] == '+')
op = 1;
else if (s[i] == '-')
op = -1;
else {//数字
int t = 0;
do {
t *= 10;
t += s[i++] - '0';
} while (i < len && s[i] >= '0' && s[i] <= '9');
i--;
result += op * t;
}
}
return result;
}
};
[/code]
```code
//计算器Ⅱ
class Solution {
public:
int calculate(string s) {
stack<int>sta;//存储中间结果的栈
char sign='+';//存储操作状态
int temp=0,res=0;
for (int i = 0; i < s.size(); ++i) {
if (s[i] >= '0') {//加减乘除和空格的ASCII码都小于‘0’
temp = temp * 10 - '0' + s[i];//进位
}
if ((s[i] < '0' && s[i] != ' ') || i == s.size() - 1) {
if (sign == '+')
sta.push(temp);
else if(sign == '-')
sta.push(-temp);
else if (sign == '*' || sign == '/') {
int tmp = sign == '*' ? sta.top() * temp : sta.top() / temp;
sta.pop();
sta.push(tmp);
}
sign = s[i];//保存当前符号
temp = 0;//从零开始计算下一位数字
}
}
for (; !sta.empty(); sta.pop())
res += sta.top();
return res;
}
};
[/code]
```code
//计算器Ⅲ
class Solution {
public:
int calculate(string s) {
stack<int>sta;//存储中间结果的栈
char sign='+';//存储操作状态
int temp=0,res=0;
for (int i = 0; i < s.size(); ++i) {
if (s[i] >= '0' && s[i]<='9') {//加减乘除和空格的ASCII码都小于‘0’
temp = temp * 10 + s[i] - '0';//进位
}
else if(s[i]=='('){
int j = i,count=0;
for (; i < s.size(); ++i) {
if (s[i] == '(') ++count;
if (s[i] == ')') --count;
if (count == 0) break;
}
temp = calculate(s.substr(j + 1, i - j - 1));
}
if ((s[i] < '0' && s[i] != ' ') || i == s.size() - 1) {
if (sign == '+')
sta.push(temp);
else if(sign == '-')
sta.push(-temp);
else if (sign == '*' || sign == '/') {
int tmp = sign == '*' ? sta.top() * temp : sta.top() / temp;
sta.pop();
sta.push(tmp);
}
sign = s[i];//保存当前符号
temp = 0;//从零开始计算下一位数字
}
}
for (; !sta.empty(); sta.pop())
res += sta.top();
return res;
}
};
[/code]
## 2-5 数据结构与算法 - 字符串匹配
```code
#!/usr/bin/python
import numpy as np
# 计算编辑距离(Levenshtein Distance):描述由一个字串转化成另一个字串最少的操作次数
# 在其中的操作包括插入、删除、替换
def levenshtein_ratio_and_distance(s, t, ratio_calc=False):
# 初始化零矩阵
rows = len(s) + 1
cols = len(t) + 1
distance = np.zeros((rows, cols), dtype=int)
# 用两个字符串的每个字符的索引填充零矩阵
for i in range(1, rows):
for k in range(1, cols):
distance[i][0] = i
distance[0][k] = k
# 迭代矩阵以计算删除、插入和/或替换的成本
for col in range(1, cols):
for row in range(1, rows):
cost = 0 # 如果给定位置[i,j]的两个字符串中的字符相同,则代价为0
else:
if ratio_calc == True:
cost = 2
else:
cost = 1
distance[row][col] = min(distance[row - 1][col] + 1, # 删除的成本
distance[row][col - 1] + 1, # 插入的成本
distance[row - 1][col - 1] + cost) # 插入的成本
if ratio_calc == True:
Ratio = ((len(s) + len(t)) - distance[row][col]) / (len(s) + len(t))
return Ratio
else:
return "the strings are {} edits away".format(distance[row][col])
Str1 = "Apple Inc."
Str2 = "apple Inc"
Distance = levenshtein_ratio_and_distance(Str1,Str2)
print(Distance)
Ratio = levenshtein_ratio_and_distance(Str1,Str2,ratio_calc = True)
print(Ratio)
[/code]
## 2-6 数据结构与算法 - 排序
## 2-7 数据结构与算法 - 查找
## 2-8 数据结构与算法 - 树
## 2-9 数据结构与算法 - 图
# 3、数据库原理与应用(MySQL)
## 3-1 MySQL数据库 - 初识MySQL
## 3-2 MySQL数据库 - 数据库和表的基本操作
## 3-3 MySQL数据库 - 数据库和表的基本操作(二)
## 3-4 MySQL数据库 - 单表查询(一)
## 3-5 MySQL数据库 - 单表查询(二)
## 3-6 MySQL数据库 - 单表查询(三)
4、数据采集(爬虫)
4-1 Python入门之正则表达式
4-2 网页抓取及信息提取
4-3 Scrapy爬虫(一)Educoder 网站图片爬取
4-4 Scrapy爬虫(二)热门网站数据爬取
5、分布式系统Hadoop
5-1 Hadoop开发环境搭建
5-2 大数据从入门到实战 - 第2章 分布式文件系统HDFS
5-3 大数据从入门到实战 - 第3章 MapReduce基础实战
5-4 HDFS和MapReduce综合实训
6、分布式数据库Hbase
6-1 HBase的安装与简单操作
6-2 HBase 伪分布式环境搭建
6-3 HBase完全分布式集群搭建
6-4 HBase 开发:使用Java操作HBase
6-5 HBase 开发:批量操作
6-6 HBase开发: Java API 管理表
6-7 HBase开发:表的扫描与扫描的缓存和批量处理
6-8 HBase高级特性:过滤器(一)
6-9 HBase高级特性:过滤器(二)
6-10 HBase综合测试
7、数据仓库工具Hive
7-1 Hive的安装与配置
7-2 Hive表DDL操作(一)
7-3 Hive表DDL操作(二)
7-4 Hive基本查询操作(一)
7-5 Hive基本查询操作(二)
7-6 Hive 表 DML 操作
8、机器学习与核心算法
8-1 Numpy初体验
8-2 Pandas初体验
8-3 Python机器学习软件包Scikit-Learn的学习与运用
8-4 SVM支持向量机学习实训
8-5 K-means聚类算法
8-6 理解机器学习基本概念:从电影评分预测讲起
9、大数据分析与挖掘(Spark)
9-1 Spark的安装与使用
9-2 Spark任务提交
9-3 算子概述
9-4 RDD的创建 -Java
9-5 RDD的创建 -Scala
9-6 RDD的创建 - Python
9-7 Spark算子--Scala版本
9-8 Spark算子综合案例 - Scala篇
9-9 Spark案例剖析 - 谷歌网页排名引擎PageRank实战
9-10 SparkSQL简单使用
9-11 SparkSQL数据源
9-12 Spark Streaming
9-13 Spark机器学习
9-14 Spark Streaming编程实战
9-15 Spark GraphX—寻找社交媒体中的“影响力用户”
9-16 Spark GraphX—构建图及相关操作
9-17 Spark GraphX—预测社交圈子
10、数据可视化显示
10-1 Python 计算思维训练——数组计算与曲线绘制
10-2 Python 计算思维训练——绘图进阶
10-3 Python计算思维训练——数组和曲线绘制练习(一)
10-4 Python计算思维训练——数组和曲线绘制练习(二)
10-5 Echarts开源库实现绘图
10-6 Echarts 显示数据库表数据
10-7 Scrapy爬虫(三)拉勾网招聘数据分析
11、Docker入门
11-1 Docker基础实战教程一:入门
11-2 Docker基础实战教程二:镜像管理
11-3 Docker基础实战教程三:Dockerfile
11-4 Docker基础实战教程四:数据卷操作
12、非关系型数据库MongoDB
12-1 初识 MongoDB
12-2 MongoDB实验——文档的高级查询操作
12-3 MongoDB实验——数据库基本操作
12-4 MongoDB之聚合函数查询统计
12-5 MongoDB之滴滴、膜拜都在用的索引
12-6 MongoDB复制集&分片
12-7 MongoDB数据库安全
12-8 MongoDB实验——数据备份和恢复
12-9 MongoDB实验——数据库优化
13、人脸识别系统
13-1 人脸识别系统 —— OpenCV人脸检测
13-2 人脸识别系统——Dlib人脸检测
13-3 人脸识别系统——Dlib人脸特征提取
13-4 人脸识别系统——Dlib人脸识别
13-5 人脸识别系统——Face recognition 人脸识别
14、旅游网站大数据分析系统项目实战
14-1 旅游网站大数据分析 - 数据抓取
14-2 旅游网站大数据分析 - 数据清洗
14-3 旅游网站大数据分析 - 数据存储
14-4 旅游网站之数据分析
14-5 旅游网站之数据可视化
15、企业岗位需求决策项目实战
15-1 企业岗位需求决策(一):数据采集
15-2 企业岗位需求决策(二):数据清洗
15-3 企业岗位需求决策(三):数据可视化
16、共享单车大数据分析系统项目实战
16-1 共享单车之数据存储
16-2 共享单车之数据分析
16-3 共享单车之数据可视化
16-4 共享单车之租赁需求预估
