| @@ -6,3 +6,46 @@ Alogrithm/.vs/Alogrithm/v16/TestStore/1/testlog.manifest | |||||
| Alogrithm/.vs/Alogrithm/v16/TestStore/2/000.testlog | Alogrithm/.vs/Alogrithm/v16/TestStore/2/000.testlog | ||||
| Alogrithm/.vs/Alogrithm/v16/TestStore/2/testlog.manifest | Alogrithm/.vs/Alogrithm/v16/TestStore/2/testlog.manifest | ||||
| Alogrithm/.vs/Alogrithm/v16/ipch/AutoPCH/c09df40e8d43ddea/MAIN.ipch | Alogrithm/.vs/Alogrithm/v16/ipch/AutoPCH/c09df40e8d43ddea/MAIN.ipch | ||||
| .vs/ProjectSettings.json | |||||
| .vs/slnx.sqlite | |||||
| .vs/VSWorkspaceState.json | |||||
| Alogrithm/.vs/Alogrithm/v16/Solution.VC.db | |||||
| Alogrithm/.vs/Alogrithm/v16/ipch/a4e78806f8e90de7.ipch | |||||
| Alogrithm/.vs/Alogrithm/v16/ipch/a9bd1b0c07fd7d97.ipch | |||||
| Alogrithm/.vs/Alogrithm/v16/ipch/AutoPCH/68cf552fa8251aa6/2_EXCELSHEETCOLUMNTITLE.ipch | |||||
| Alogrithm/.vs/Alogrithm/v16/ipch/AutoPCH/907a8f897d64c1f1/1_CONTAINSNEARBYDUPLICATE.ipch | |||||
| Alogrithm/.vs/Alogrithm/v16/ipch/AutoPCH/ef33c62a547d2002/1_CONTAINSNEARBYDUPLICATE.ipch | |||||
| Alogrithm/.vs/Alogrithm/v16/ipch/AutoPCH/f25efc4d6f84971c/MAIN.ipch | |||||
| Alogrithm/.vs/Alogrithm/v16/ipch/AutoPCH/f97b2c42bb795e41/2_EXCELSHEETCOLUMNTITLE.ipch | |||||
| Alogrithm/.vs/Alogrithm/v16/ipch/AutoPCH/fb28aefeba7b8b20/1_CONTAINSNEARBYDUPLICATE.ipch | |||||
| Alogrithm/.vs/Alogrithm/v16/TestStore/3/000.testlog | |||||
| Alogrithm/.vs/Alogrithm/v16/TestStore/3/testlog.manifest | |||||
| Alogrithm/Alogrithm/Debug/1_ContainsNearbyDuplicate.obj | |||||
| Alogrithm/Alogrithm/Debug/2_ExcelSheetColumnTitle.obj | |||||
| Alogrithm/Alogrithm/Debug/Alogrithm.Build.CppClean.log | |||||
| Alogrithm/Alogrithm/Debug/Alogrithm.exe.recipe | |||||
| Alogrithm/Alogrithm/Debug/Alogrithm.log | |||||
| Alogrithm/Alogrithm/Debug/Alogrithm.vcxproj.FileListAbsolute.txt | |||||
| Alogrithm/Alogrithm/Debug/main.obj | |||||
| Alogrithm/Alogrithm/Debug/vc142.idb | |||||
| Alogrithm/Alogrithm/Debug/vc142.pdb | |||||
| Alogrithm/Alogrithm/Debug/Alogrithm.tlog/Alogrithm.lastbuildstate | |||||
| Alogrithm/Alogrithm/Debug/Alogrithm.tlog/CL.command.1.tlog | |||||
| Alogrithm/UnitTest/Debug/pch.obj | |||||
| Alogrithm/UnitTest/Debug/UnitTest.log | |||||
| Alogrithm/UnitTest/Debug/UnitTest.pch | |||||
| Alogrithm/UnitTest/Debug/vc142.idb | |||||
| Alogrithm/UnitTest/Debug/vc142.pdb | |||||
| Alogrithm/UnitTest/Debug/UnitTest.tlog/CL.command.1.tlog | |||||
| Alogrithm/UnitTest/Debug/UnitTest.tlog/CL.read.1.tlog | |||||
| Alogrithm/UnitTest/Debug/UnitTest.tlog/CL.write.1.tlog | |||||
| Alogrithm/UnitTest/Debug/UnitTest.tlog/UnitTest.lastbuildstate | |||||
| Alogrithm/UnitTest/Debug/UnitTest.tlog/unsuccessfulbuild | |||||
| Alogrithm/Alogrithm/Debug/Alogrithm.tlog/CL.read.1.tlog | |||||
| Alogrithm/Alogrithm/Debug/Alogrithm.tlog/CL.write.1.tlog | |||||
| Alogrithm/Alogrithm/Debug/Alogrithm.tlog/link.command.1.tlog | |||||
| Alogrithm/Alogrithm/Debug/Alogrithm.tlog/link.read.1.tlog | |||||
| Alogrithm/Alogrithm/Debug/Alogrithm.tlog/link.write.1.tlog | |||||
| Alogrithm/Debug/Alogrithm.exe | |||||
| Alogrithm/Debug/Alogrithm.ilk | |||||
| Alogrithm/Debug/Alogrithm.pdb | |||||
| @@ -0,0 +1,11 @@ | |||||
| [Test1] | |||||
| nums=1,2,3,1 | |||||
| nExpect=1 | |||||
| [Test1] | |||||
| nums=1,0,1,1 | |||||
| nExpect=1 | |||||
| [Test3] | |||||
| nums=1,2,3,1,2,3 | |||||
| nExpect=0 | |||||
| @@ -0,0 +1,2 @@ | |||||
| #pragma once | |||||
| bool ContainsNearbyDuplicate(int* nums, int numsSize, int k); | |||||
| @@ -0,0 +1,5 @@ | |||||
| #pragma once | |||||
| #include <stdio.h> | |||||
| #include <string.h> | |||||
| char* ExcelSheetColumnTitle(int n); | |||||
| @@ -0,0 +1,66 @@ | |||||
| #include <stdio.h> | |||||
| #include <stdlib.h> | |||||
| #include "../include/1_ContainsNearbyDuplicate.h" | |||||
| //解题思路:先排序,再查找,再判断 | |||||
| typedef struct node_t { //定义结构体数组类型 | |||||
| int value; //存放 数组值 | |||||
| int index; //存放 下标 | |||||
| }node; | |||||
| int cmp(const void* a, const void* b) //qsort 里的cmp函数 | |||||
| { | |||||
| if (((node*)a)->value < ((node*)b)->value) | |||||
| return -1; | |||||
| else if (((node*)a)->value == ((node*)b)->value) | |||||
| return 0; | |||||
| else | |||||
| return 1; | |||||
| } | |||||
| int fun(int a, int b) //两数相减求绝对值 | |||||
| { | |||||
| int t; | |||||
| t = a - b; | |||||
| if (t < 0) | |||||
| t = t - 2 * t; | |||||
| return t; | |||||
| } | |||||
| bool ContainsNearbyDuplicate(int* nums, int numsSize, int k) | |||||
| { | |||||
| node* arr = NULL; //定义一个node 指针 | |||||
| int i = 0; | |||||
| int j = 0; | |||||
| arr = (node*)malloc(sizeof(node) * 100000);//为arr指针分配足够空间,用来保存数组 | |||||
| if (NULL == arr) | |||||
| { | |||||
| printf("内存分配失败\n"); | |||||
| } | |||||
| else | |||||
| { | |||||
| for (i = 0; i < numsSize; i++)//遍历数组nums,把nums里的值和对应的下标保存在arr中 | |||||
| { | |||||
| arr[i].value = nums[i]; | |||||
| arr[i].index = i; | |||||
| } | |||||
| qsort(arr, numsSize, sizeof(node), cmp);//调用c库函数qsort,对得到的数组arr进行排序 | |||||
| for (i = 0; i < numsSize; i++)//对排好序的数组arr遍历,寻找返回true的条件 | |||||
| { | |||||
| for (j = i + 1; j < numsSize; j++) | |||||
| { | |||||
| if (arr[i].value == arr[j].value) //第i个元素和i后面的元素作比较,判断值是否相等 | |||||
| { | |||||
| if (fun(arr[j].index, arr[i].index) <= k)//调用fun,求得下标差的绝对值,和k作比较 | |||||
| { | |||||
| return true; | |||||
| } | |||||
| } | |||||
| else {//不符合则跳出循环 | |||||
| break; | |||||
| } | |||||
| } | |||||
| } | |||||
| } | |||||
| free(arr);//释放arr | |||||
| return false;//循环执完以后,说明没有符合的结果,则返回false; | |||||
| } | |||||
| @@ -0,0 +1,20 @@ | |||||
| #include "../include/2_ExcelSheetColumnTitle.h" | |||||
| #define STR_LEN 100 | |||||
| //给定一个整数,返回它在 Excel 表中相对应的列名称,如果在Excel表中找不到该列,则返回""。 | |||||
| char* ExcelSheetColumnTitle(int n) | |||||
| { | |||||
| char str[STR_LEN] = { 0 }; | |||||
| int i = 0; | |||||
| while (n > 0) { | |||||
| if ((n > 0) && (n <= 26)) { | |||||
| str[i] = 'A' + n - 1; | |||||
| } | |||||
| else if (n > 26) { | |||||
| str[i] = 'A'; | |||||
| } | |||||
| n = n - 26; | |||||
| i++; | |||||
| } | |||||
| printf("%s", str); | |||||
| return str; | |||||
| } | |||||
| @@ -0,0 +1,6 @@ | |||||
| #include "../include/2_ExcelSheetColumnTitle.h" | |||||
| int main() | |||||
| { | |||||
| ExcelSheetColumnTitle(10); | |||||
| return 0; | |||||
| } | |||||
| @@ -0,0 +1,29 @@ | |||||
| #include "pch.h" | |||||
| #include "CppUnitTest.h" | |||||
| #define FilePath "../Alogrithm/1_ContainsNearbyDuplicate.ini" | |||||
| using namespace Microsoft::VisualStudio::CppUnitTestFramework; | |||||
| namespace UnitTest | |||||
| { | |||||
| TEST_CLASS(UnitTest) | |||||
| { | |||||
| public: | |||||
| TEST_METHOD(TestMethode1) | |||||
| { | |||||
| char str[50][10] = { 0 };//保存ini文件里 节的名字 | |||||
| int count = CalcCount(50, str);//保存ini文件里 节的个数 | |||||
| bool nReal;//保存运算结果 | |||||
| CString na, nb, nExpect; //b保存不同的键值 | |||||
| for (int j = 0; j < count; j++) | |||||
| { | |||||
| GetPrivateProfileString(str[j], "na", " ", na.GetBuffer(20), 20, FilePath); | |||||
| GetPrivateProfileString(str[j], "nExpect", " ", nExpect.GetBuffer(20), 20, FilePath); | |||||
| nReal = add(_ttoi64(na), _ttoi64(nb)); //_ttoi是CString转为整型 | |||||
| Assert::AreEqual(nReal, _ttoi64(nExpect)); | |||||
| } | |||||
| } | |||||
| }; | |||||
| } | |||||
| @@ -0,0 +1,173 @@ | |||||
| <?xml version="1.0" encoding="utf-8"?> | |||||
| <Project DefaultTargets="Build" 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>16.0</VCProjectVersion> | |||||
| <ProjectGuid>{BABADA8A-F1CD-4EAA-9392-D0B01F8DF7A4}</ProjectGuid> | |||||
| <Keyword>Win32Proj</Keyword> | |||||
| <RootNamespace>UnitTest</RootNamespace> | |||||
| <WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion> | |||||
| <ProjectSubType>NativeUnitTestProject</ProjectSubType> | |||||
| </PropertyGroup> | |||||
| <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" /> | |||||
| <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration"> | |||||
| <ConfigurationType>DynamicLibrary</ConfigurationType> | |||||
| <UseDebugLibraries>true</UseDebugLibraries> | |||||
| <PlatformToolset>v142</PlatformToolset> | |||||
| <CharacterSet>MultiByte</CharacterSet> | |||||
| <UseOfMfc>false</UseOfMfc> | |||||
| </PropertyGroup> | |||||
| <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration"> | |||||
| <ConfigurationType>DynamicLibrary</ConfigurationType> | |||||
| <UseDebugLibraries>false</UseDebugLibraries> | |||||
| <PlatformToolset>v142</PlatformToolset> | |||||
| <WholeProgramOptimization>true</WholeProgramOptimization> | |||||
| <CharacterSet>Unicode</CharacterSet> | |||||
| <UseOfMfc>false</UseOfMfc> | |||||
| </PropertyGroup> | |||||
| <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration"> | |||||
| <ConfigurationType>DynamicLibrary</ConfigurationType> | |||||
| <UseDebugLibraries>true</UseDebugLibraries> | |||||
| <PlatformToolset>v142</PlatformToolset> | |||||
| <CharacterSet>Unicode</CharacterSet> | |||||
| <UseOfMfc>false</UseOfMfc> | |||||
| </PropertyGroup> | |||||
| <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration"> | |||||
| <ConfigurationType>DynamicLibrary</ConfigurationType> | |||||
| <UseDebugLibraries>false</UseDebugLibraries> | |||||
| <PlatformToolset>v142</PlatformToolset> | |||||
| <WholeProgramOptimization>true</WholeProgramOptimization> | |||||
| <CharacterSet>Unicode</CharacterSet> | |||||
| <UseOfMfc>false</UseOfMfc> | |||||
| </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> | |||||
| <SDLCheck>true</SDLCheck> | |||||
| <AdditionalIncludeDirectories>$(VCInstallDir)UnitTest\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> | |||||
| <PreprocessorDefinitions>WIN32;_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions> | |||||
| <UseFullPaths>true</UseFullPaths> | |||||
| <PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile> | |||||
| </ClCompile> | |||||
| <Link> | |||||
| <SubSystem>Windows</SubSystem> | |||||
| <AdditionalLibraryDirectories>$(VCInstallDir)UnitTest\lib;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories> | |||||
| </Link> | |||||
| </ItemDefinitionGroup> | |||||
| <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'"> | |||||
| <ClCompile> | |||||
| <PrecompiledHeader>Use</PrecompiledHeader> | |||||
| <WarningLevel>Level3</WarningLevel> | |||||
| <SDLCheck>true</SDLCheck> | |||||
| <AdditionalIncludeDirectories>$(VCInstallDir)UnitTest\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> | |||||
| <PreprocessorDefinitions>_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions> | |||||
| <UseFullPaths>true</UseFullPaths> | |||||
| <PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile> | |||||
| </ClCompile> | |||||
| <Link> | |||||
| <SubSystem>Windows</SubSystem> | |||||
| <AdditionalLibraryDirectories>$(VCInstallDir)UnitTest\lib;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories> | |||||
| </Link> | |||||
| </ItemDefinitionGroup> | |||||
| <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> | |||||
| <ClCompile> | |||||
| <PrecompiledHeader>Use</PrecompiledHeader> | |||||
| <WarningLevel>Level3</WarningLevel> | |||||
| <FunctionLevelLinking>true</FunctionLevelLinking> | |||||
| <IntrinsicFunctions>true</IntrinsicFunctions> | |||||
| <SDLCheck>true</SDLCheck> | |||||
| <AdditionalIncludeDirectories>$(VCInstallDir)UnitTest\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> | |||||
| <PreprocessorDefinitions>WIN32;NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions> | |||||
| <UseFullPaths>true</UseFullPaths> | |||||
| <PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile> | |||||
| </ClCompile> | |||||
| <Link> | |||||
| <SubSystem>Windows</SubSystem> | |||||
| <EnableCOMDATFolding>true</EnableCOMDATFolding> | |||||
| <OptimizeReferences>true</OptimizeReferences> | |||||
| <AdditionalLibraryDirectories>$(VCInstallDir)UnitTest\lib;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories> | |||||
| </Link> | |||||
| </ItemDefinitionGroup> | |||||
| <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'"> | |||||
| <ClCompile> | |||||
| <PrecompiledHeader>Use</PrecompiledHeader> | |||||
| <WarningLevel>Level3</WarningLevel> | |||||
| <FunctionLevelLinking>true</FunctionLevelLinking> | |||||
| <IntrinsicFunctions>true</IntrinsicFunctions> | |||||
| <SDLCheck>true</SDLCheck> | |||||
| <AdditionalIncludeDirectories>$(VCInstallDir)UnitTest\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> | |||||
| <PreprocessorDefinitions>NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions> | |||||
| <UseFullPaths>true</UseFullPaths> | |||||
| <PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile> | |||||
| </ClCompile> | |||||
| <Link> | |||||
| <SubSystem>Windows</SubSystem> | |||||
| <EnableCOMDATFolding>true</EnableCOMDATFolding> | |||||
| <OptimizeReferences>true</OptimizeReferences> | |||||
| <AdditionalLibraryDirectories>$(VCInstallDir)UnitTest\lib;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories> | |||||
| </Link> | |||||
| </ItemDefinitionGroup> | |||||
| <ItemGroup> | |||||
| <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> | |||||
| <ClCompile Include="UnitTest.cpp" /> | |||||
| </ItemGroup> | |||||
| <ItemGroup> | |||||
| <ClInclude Include="pch.h" /> | |||||
| </ItemGroup> | |||||
| <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> | |||||
| <ImportGroup Label="ExtensionTargets"> | |||||
| </ImportGroup> | |||||
| </Project> | |||||
| @@ -0,0 +1,30 @@ | |||||
| <?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;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx</Extensions> | |||||
| </Filter> | |||||
| <Filter Include="头文件"> | |||||
| <UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier> | |||||
| <Extensions>h;hh;hpp;hxx;h++;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> | |||||
| <ClCompile Include="UnitTest.cpp"> | |||||
| <Filter>源文件</Filter> | |||||
| </ClCompile> | |||||
| <ClCompile Include="pch.cpp"> | |||||
| <Filter>源文件</Filter> | |||||
| </ClCompile> | |||||
| </ItemGroup> | |||||
| <ItemGroup> | |||||
| <ClInclude Include="pch.h"> | |||||
| <Filter>头文件</Filter> | |||||
| </ClInclude> | |||||
| </ItemGroup> | |||||
| </Project> | |||||
| @@ -0,0 +1,4 @@ | |||||
| <?xml version="1.0" encoding="utf-8"?> | |||||
| <Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | |||||
| <PropertyGroup /> | |||||
| </Project> | |||||
| @@ -0,0 +1,59 @@ | |||||
| // pch.cpp: 与预编译标头对应的源文件 | |||||
| #include "pch.h" | |||||
| int CalcCount(int n, char(*str)[10]) | |||||
| { | |||||
| TCHAR chSectionNames[2048] = { 0 };//定义一个数组,保存读取节的名字 | |||||
| char* pSectionName; //保存找到的某个节名字符串的首地址 | |||||
| int i = 0; //i指向数组chSectionNames的某个位置,从0开始,顺序后移 | |||||
| int j = 0; //j用来保存下一个节名字符串的首地址相对于当前i的位置偏移量 | |||||
| int k = 0; //临时变量,用于给str数组赋值 | |||||
| int m = 0; //临时变量,用于给str数组赋值 | |||||
| int count = 0; //统计节的个数 | |||||
| GetPrivateProfileSectionNames(chSectionNames, 2048, "..//ex1.ini");//获取文件中的节名,每个节名以"\0"分割,保存在chSectionNames中 | |||||
| //要加头文件 | |||||
| for (i = 0; i < 2048; i++, j++)//对chSectionName中保存的内容进行拆分 | |||||
| { | |||||
| if (chSectionNames[0] == '\0')//如果第一个字符就是0,则说明ini中一个节也没有, | |||||
| { | |||||
| break; | |||||
| } | |||||
| if (chSectionNames[i] == '\0') | |||||
| { | |||||
| count++; | |||||
| pSectionName = &chSectionNames[i - j]; //找到一个0,则说明从这个字符往前,减掉j个偏移量, | |||||
| //就是一个节名的首地址 | |||||
| j = -1; //找到一个节名后,j的值要还原,以统计下一个节名地址的偏移量 | |||||
| //赋成-1是因为节名字符串的最后一个字符0是终止符,不能作为节名 | |||||
| for (m = 0; m <= strlen(pSectionName); m++)//把找到的节名保存到str中 | |||||
| { | |||||
| str[k][m] = *(pSectionName + m); | |||||
| } | |||||
| //str[k][++m] = '\0';//手动给节名加上\0,表示这个节名结束 | |||||
| k++;//变量自加,用来保存下一个节名 | |||||
| //在获取节名的时候可以获取该节中键的值,前提是我们知道该节中有哪些键。 | |||||
| if (chSectionNames[i + 1] == 0) | |||||
| { | |||||
| break; //当两个相邻的字符都是0时,则所有的节名都已找到,循环终止 | |||||
| } | |||||
| } | |||||
| } | |||||
| return count;//返回节名的个数 | |||||
| } | |||||
| int* str_device(CString* str, int* value_count) | |||||
| { | |||||
| char* token; //存放被切割后的第一个子串 | |||||
| static int Section_devide[500];//存放字符切割完成以后的数组元素值 | |||||
| char Section_value[500] = { 0 };//存放nums转换成string类型的结果 | |||||
| strcpy(Section_value, *str);//将CString类型的字符串转换成char类型,方便后面切割字符串 | |||||
| //获得切割到的第一个字符串 | |||||
| token = strtok(Section_value, ","); | |||||
| /* 继续获取其他的子字符串 */ | |||||
| while (token != NULL) { | |||||
| Section_devide[*value_count] = (_ttoi)(token);//把切割得到的子串转为int,存到数组中去。 | |||||
| token = strtok(NULL, ","); | |||||
| (*value_count)++; //记录存了多少个元素 | |||||
| } | |||||
| return Section_devide; //返回数组首地址 | |||||
| } | |||||
| @@ -0,0 +1,20 @@ | |||||
| // pch.h: 这是预编译标头文件。 | |||||
| // 下方列出的文件仅编译一次,提高了将来生成的生成性能。 | |||||
| // 这还将影响 IntelliSense 性能,包括代码完成和许多代码浏览功能。 | |||||
| // 但是,如果此处列出的文件中的任何一个在生成之间有更新,它们全部都将被重新编译。 | |||||
| // 请勿在此处添加要频繁更新的文件,这将使得性能优势无效。 | |||||
| #ifndef PCH_H | |||||
| #define PCH_H | |||||
| #include <stdio.h> | |||||
| #include <stdlib.h> | |||||
| #include <string.h> | |||||
| #include<Windows.h> | |||||
| #include <atlstr.h> | |||||
| int CalcCount(int n, char(*str)[10]); | |||||
| int* str_device(CString* str, int* value_count); | |||||
| #endif //PCH_H | |||||