Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added Skewary/Cal/.vs/Cal/v15/.suo
Binary file not shown.
Binary file added Skewary/Cal/.vs/Cal/v15/Browse.VC.db
Binary file not shown.
Binary file added Skewary/Cal/.vs/Cal/v15/Solution.VC.db
Binary file not shown.
Binary file added Skewary/Cal/.vs/Cal/v15/Solution.VC.db-shm
Binary file not shown.
Binary file added Skewary/Cal/.vs/Cal/v15/Solution.VC.db-wal
Binary file not shown.
Binary file not shown.
Binary file not shown.
41 changes: 41 additions & 0 deletions Skewary/Cal/Cal.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.28307.779
MinimumVisualStudioVersion = 10.0.40219.1
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ConsoleApplication1", "ConsoleApplication1\ConsoleApplication1.vcxproj", "{31B0A1BB-1F71-4FBA-9500-BDF112C504AA}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "caltest", "caltest\caltest.vcxproj", "{6B1898DB-6824-44D6-A56D-2DF4FF671ECB}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|x64 = Debug|x64
Debug|x86 = Debug|x86
Release|x64 = Release|x64
Release|x86 = Release|x86
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{31B0A1BB-1F71-4FBA-9500-BDF112C504AA}.Debug|x64.ActiveCfg = Debug|x64
{31B0A1BB-1F71-4FBA-9500-BDF112C504AA}.Debug|x64.Build.0 = Debug|x64
{31B0A1BB-1F71-4FBA-9500-BDF112C504AA}.Debug|x86.ActiveCfg = Debug|Win32
{31B0A1BB-1F71-4FBA-9500-BDF112C504AA}.Debug|x86.Build.0 = Debug|Win32
{31B0A1BB-1F71-4FBA-9500-BDF112C504AA}.Release|x64.ActiveCfg = Release|x64
{31B0A1BB-1F71-4FBA-9500-BDF112C504AA}.Release|x64.Build.0 = Release|x64
{31B0A1BB-1F71-4FBA-9500-BDF112C504AA}.Release|x86.ActiveCfg = Release|Win32
{31B0A1BB-1F71-4FBA-9500-BDF112C504AA}.Release|x86.Build.0 = Release|Win32
{6B1898DB-6824-44D6-A56D-2DF4FF671ECB}.Debug|x64.ActiveCfg = Debug|x64
{6B1898DB-6824-44D6-A56D-2DF4FF671ECB}.Debug|x64.Build.0 = Debug|x64
{6B1898DB-6824-44D6-A56D-2DF4FF671ECB}.Debug|x86.ActiveCfg = Debug|Win32
{6B1898DB-6824-44D6-A56D-2DF4FF671ECB}.Debug|x86.Build.0 = Debug|Win32
{6B1898DB-6824-44D6-A56D-2DF4FF671ECB}.Release|x64.ActiveCfg = Release|x64
{6B1898DB-6824-44D6-A56D-2DF4FF671ECB}.Release|x64.Build.0 = Release|x64
{6B1898DB-6824-44D6-A56D-2DF4FF671ECB}.Release|x86.ActiveCfg = Release|Win32
{6B1898DB-6824-44D6-A56D-2DF4FF671ECB}.Release|x86.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {DC9A7168-5214-466A-A3D7-6461E5F72EA1}
EndGlobalSection
EndGlobal
18 changes: 18 additions & 0 deletions Skewary/Cal/ConsoleApplication1/Calculator.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#pragma once
#include "pch.h"
#include <stack>
#include <vector>
#include <iostream>
#include "stdlib.h"
#include <ctime>
#include <string>
using namespace std;

class Calculator {
private:
string op[4] = { "+", "-", "*", "/" };
public:
Calculator();
string MakeFormula();
string Solve(string formula);
};
118 changes: 118 additions & 0 deletions Skewary/Cal/ConsoleApplication1/ConsoleApplication1.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@


#include "pch.h"
#include <stack>
#include <vector>
#include <iostream>
#include "stdlib.h"
#include <ctime>
#include <string>
#include "Calculator.h"

#define random(a,b) (rand()%(b-a+1)+a)

using namespace std;

Calculator::Calculator() {}

string Calculator::MakeFormula() {
string formula = "";
srand((unsigned int)time(NULL));
int count = random(1, 3);
int start = 0;
int number1 = random(1, 100);
formula += to_string(number1);
while (start <= count) {
int operation = random(0, 3);
int number2 = random(1, 100);
formula += op[operation] + to_string(number2);
start++;
}
return formula;
};

string Calculator::Solve(string formula) {
vector<string>* tempStack = new vector<string>();
stack<char>* operatorStack = new stack<char>();
int len = formula.length();
int k = 0;
for (int j = -1; j < len - 1; j++) {
char formulaChar = formula[j + 1];
if (j == len - 2 || formulaChar == '+' || formulaChar == '-' ||
formulaChar == '*' || formulaChar == '/') {
if (j == len - 2) {
tempStack->push_back(formula.substr(k));//last number
}
else {
if (k <= j) {
tempStack->push_back(formula.substr(k, j + 1));
}
if (operatorStack->empty()) {
operatorStack->push(formulaChar);
}
else {
char stackChar = operatorStack->top();
if ((stackChar == '+' || stackChar == '-')
&& (formulaChar == '*' || formulaChar == '/')) {
operatorStack->push(formulaChar);
}
else {
tempStack->push_back(string(1, stackChar));
operatorStack->pop();
operatorStack->push(formulaChar);
}
}
}
k = j + 2;
}
}
while (!operatorStack->empty()) {
tempStack->push_back(string(1, operatorStack->top()));
operatorStack->pop();
}
stack<string>* calcStack = new stack<string>();
for (int i = 0; i < tempStack->size(); i++) {
string peekChar = tempStack->at(i);
if (peekChar != "+" && peekChar != "-"
&& peekChar != "/" && peekChar != "*") {
calcStack->push(peekChar);
}
else {
int a1 = 0;
int b1 = 0;
if (!calcStack->empty()) {
b1 = stoi(calcStack->top());
calcStack->pop();
}
if (!calcStack->empty()) {
a1 = stoi(calcStack->top());
calcStack->pop();
}
if (peekChar == "+") {
calcStack->push(to_string(a1 + b1));
}
else if (peekChar == "-") {
calcStack->push(to_string(a1 - b1));
}
else if (peekChar == "*") {
calcStack->push(to_string(a1 * b1));
}
else if (peekChar == "/") {
calcStack->push(to_string(a1 / b1));
}
}
}
return formula + "=" + calcStack->top();
}

int main()
{
Calculator* calc = new Calculator();
string question = calc->MakeFormula();
cout << question << endl;
string ret = calc->Solve("11+22");
cout << ret << endl;
getchar();
}


169 changes: 169 additions & 0 deletions Skewary/Cal/ConsoleApplication1/ConsoleApplication1.vcxproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,169 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Debug|x64">
<Configuration>Debug</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|x64">
<Configuration>Release</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
<VCProjectVersion>15.0</VCProjectVersion>
<ProjectGuid>{31B0A1BB-1F71-4FBA-9500-BDF112C504AA}</ProjectGuid>
<Keyword>Win32Proj</Keyword>
<RootNamespace>ConsoleApplication1</RootNamespace>
<WindowsTargetPlatformVersion>10.0.17763.0</WindowsTargetPlatformVersion>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v141</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v141</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v141</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v141</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Label="Shared">
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<LinkIncremental>true</LinkIncremental>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<LinkIncremental>true</LinkIncremental>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<LinkIncremental>false</LinkIncremental>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<LinkIncremental>false</LinkIncremental>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<PrecompiledHeader>Use</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<ClCompile>
<PrecompiledHeader>Use</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<PrecompiledHeader>Use</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<Optimization>MaxSpeed</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<ClCompile>
<PrecompiledHeader>Use</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<Optimization>MaxSpeed</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClInclude Include="Calculator.h" />
<ClInclude Include="pch.h" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="ConsoleApplication1.cpp" />
<ClCompile Include="pch.cpp">
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Create</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">Create</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Create</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|x64'">Create</PrecompiledHeader>
</ClCompile>
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<Filter Include="源文件">
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
<Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
</Filter>
<Filter Include="头文件">
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
<Extensions>h;hh;hpp;hxx;hm;inl;inc;ipp;xsd</Extensions>
</Filter>
<Filter Include="资源文件">
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
</Filter>
</ItemGroup>
<ItemGroup>
<ClInclude Include="pch.h">
<Filter>头文件</Filter>
</ClInclude>
<ClInclude Include="Calculator.h">
<Filter>头文件</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="pch.cpp">
<Filter>源文件</Filter>
</ClCompile>
<ClCompile Include="ConsoleApplication1.cpp">
<Filter>源文件</Filter>
</ClCompile>
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup />
</Project>
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#TargetFrameworkVersion=v4.0:PlatformToolSet=v141:EnableManagedIncrementalBuild=false:VCToolArchitecture=Native32Bit:WindowsTargetPlatformVersion=10.0.17763.0
Debug|Win32|C:\Users\叶志翔\Desktop\Calculator\Skewary\Cal\|
Binary file not shown.
Binary file not shown.
Binary file not shown.
3 changes: 3 additions & 0 deletions Skewary/Cal/ConsoleApplication1/Debug/ConsoleApplication1.log
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
 ConsoleApplication1.cpp
c:\users\叶志翔\desktop\calculator\skewary\cal\consoleapplication1\consoleapplication1.cpp(74): warning C4018: “<”: 有符号/无符号不匹配
ConsoleApplication1.vcxproj -> C:\Users\叶志翔\Desktop\Calculator\Skewary\Cal\Debug\ConsoleApplication1.exe
Binary file added Skewary/Cal/ConsoleApplication1/Debug/vc141.idb
Binary file not shown.
Binary file added Skewary/Cal/ConsoleApplication1/Debug/vc141.pdb
Binary file not shown.
Loading