Skip to content

Commit

Permalink
feat:中缀表达式运算、近似字符串查找
Browse files Browse the repository at this point in the history
  • Loading branch information
JalorOo committed Nov 27, 2020
1 parent d222146 commit 23b8a4c
Show file tree
Hide file tree
Showing 7 changed files with 147 additions and 4 deletions.
Binary file modified .DS_Store
Binary file not shown.
6 changes: 6 additions & 0 deletions ADT.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
33460298255E0B6800CAE464 /* BIGNUM.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 33460296255E0B6800CAE464 /* BIGNUM.cpp */; };
3346CF8D24FDE480005EADE7 /* main.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 3346CF8C24FDE480005EADE7 /* main.cpp */; };
338271BC250663B5003A881A /* SORT.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 338271BA250663B5003A881A /* SORT.cpp */; };
33B1065425707F5A00006A8F /* ASM.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 33B1065225707F5A00006A8F /* ASM.cpp */; };
/* End PBXBuildFile section */

/* Begin PBXCopyFilesBuildPhase section */
Expand All @@ -34,6 +35,8 @@
3346CF8C24FDE480005EADE7 /* main.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = main.cpp; sourceTree = "<group>"; };
338271BA250663B5003A881A /* SORT.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = SORT.cpp; sourceTree = "<group>"; };
338271BB250663B5003A881A /* SORT.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = SORT.hpp; sourceTree = "<group>"; };
33B1065225707F5A00006A8F /* ASM.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = ASM.cpp; sourceTree = "<group>"; };
33B1065325707F5A00006A8F /* ASM.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = ASM.hpp; sourceTree = "<group>"; };
33D3607124FF3F9B00F3DFF3 /* SEQLIST.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = SEQLIST.hpp; sourceTree = "<group>"; };
33D3607224FF614700F3DFF3 /* NODE.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = NODE.h; sourceTree = "<group>"; };
33D3607324FF61BF00F3DFF3 /* LINKLIST.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = LINKLIST.h; sourceTree = "<group>"; };
Expand Down Expand Up @@ -79,6 +82,8 @@
33460297255E0B6800CAE464 /* BIGNUM.hpp */,
33083B4F25674533007E7518 /* CALCUL.cpp */,
33083B5025674533007E7518 /* CALCUL.hpp */,
33B1065225707F5A00006A8F /* ASM.cpp */,
33B1065325707F5A00006A8F /* ASM.hpp */,
);
path = ADT;
sourceTree = "<group>";
Expand Down Expand Up @@ -142,6 +147,7 @@
files = (
3346CF8D24FDE480005EADE7 /* main.cpp in Sources */,
338271BC250663B5003A881A /* SORT.cpp in Sources */,
33B1065425707F5A00006A8F /* ASM.cpp in Sources */,
33460298255E0B6800CAE464 /* BIGNUM.cpp in Sources */,
33083B5125674533007E7518 /* CALCUL.cpp in Sources */,
);
Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
filePath = "ADT/main.cpp"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "15"
endingLineNumber = "15"
startingLineNumber = "16"
endingLineNumber = "16"
landmarkName = "main(argc, argv)"
landmarkType = "9">
</BreakpointContent>
Expand Down Expand Up @@ -388,5 +388,53 @@
landmarkType = "7">
</BreakpointContent>
</BreakpointProxy>
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
<BreakpointContent
uuid = "AE7C9BB0-E505-4A07-A5CE-7B913D1A09BB"
shouldBeEnabled = "No"
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "ADT/main.cpp"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "72"
endingLineNumber = "72"
landmarkName = "main(argc, argv)"
landmarkType = "9">
</BreakpointContent>
</BreakpointProxy>
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
<BreakpointContent
uuid = "2AA14BC4-861A-4A62-9710-AA0DF17CA05F"
shouldBeEnabled = "No"
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "ADT/ASM.cpp"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "40"
endingLineNumber = "40"
landmarkName = "ASMClass::ASMCalcul(p, t)"
landmarkType = "7">
</BreakpointContent>
</BreakpointProxy>
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
<BreakpointContent
uuid = "4D83254E-9301-4512-9795-6248F4A42EC6"
shouldBeEnabled = "No"
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "ADT/ASM.cpp"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "36"
endingLineNumber = "36"
landmarkName = "ASMClass::ASMCalcul(p, t)"
landmarkType = "7">
</BreakpointContent>
</BreakpointProxy>
</Breakpoints>
</Bucket>
52 changes: 52 additions & 0 deletions ADT/ASM.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
//
// ASM.cpp
// ADT
//
// Created by Jalor on 2020/11/27.
// Copyright © 2020 Jalor. All rights reserved.
//

#include "ASM.hpp"

int min(int a,int b,int c){
if(a > b){
a = b;
}
if(a > c){
a = c;
}
return a;
}

int ASMClass::ASMCalcul(string p,string t){
int m = p.length();
int n = t.length();
int i,j;

for (j = 0; j <= n; j++)
{
D[0][j] = 0;//样本与文本有0处不同
}

for (i = 0; i <= m;i++)
{
D[i][0] = i;//样本与文本有i处不同
}

for (j = 1; j <= n; j++)
{
for (i = 1; i <= m; i++)
{
if(p[i-1] == t[j-1]) {//若最后一个字符相等
D[i][j] = min(D[i-1][j-1], D[i-1][j]+1, D[i][j-1]+1);//样本i与文本j的最小差距应该产生在前方
//D[i-1][j-1];前字符串 比较的结果
//D[i-1][j];前 样本字符串 与 现 文本字符串 比较的结果
//D[i][j-1];现 样本字符串 与 前 文本字符串 比较的结果
} else {//若最后一个字符不相等
D[i][j] = min(D[i-1][j-1], D[i-1][j], D[i][j-1]) + 1;//样本i与文本j的最小差距应该产生在前方+1
}
}
//if(D[m][j] <= k)return j;
}
return D[m][n];
}
25 changes: 25 additions & 0 deletions ADT/ASM.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
//
// ASM.hpp
// ADT
//
// Created by Jalor on 2020/11/27.
// Copyright © 2020 Jalor. All rights reserved.
//

#ifndef ASM_hpp
#define ASM_hpp

#include <iostream>
#include <algorithm>
using namespace std;

const int ASM_MAXN = 100;

class ASMClass{
private:
int D[ASM_MAXN][ASM_MAXN];
public:
int ASMCalcul(string p,string t);
};

#endif /* ASM_hpp */
16 changes: 14 additions & 2 deletions ADT/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "LINKLIST.h"
#include "BIGNUM.hpp"
#include "CALCUL.hpp"
#include "ASM.hpp"
using namespace std;
int main(int argc, const char * argv[]) {
// cout<<"Input func(e.g: 123+456 ):"<<endl;
Expand Down Expand Up @@ -56,7 +57,18 @@ int main(int argc, const char * argv[]) {
// cout<<"="<<num1/num2<<endl;
// return 0;
// }
Calcul c = Calcul("9*9*7-1");
cout<<c.calcul()<<endl;
// Calcul c = Calcul("0*1-9");
// cout<<c.calcul()<<endl;
ASMClass a;
// cout<<"please input pattern:";
// string p;
// cin>>p;
// cout<<"please input word:";
// string t;
// cin>>t;
// int ans = a.ASMCalcul("hallo", "jalor");
int ans = a.ASMCalcul("hello", "apxgv");
// int ans = a.ASMCalcul(p, t, 100);
cout<<"found "<<ans<<" diff palces"<<endl;
return 0;
}

0 comments on commit 23b8a4c

Please sign in to comment.