Skip to content

Commit 93cb8a9

Browse files
committed
math tag
1 parent 00e27e4 commit 93cb8a9

File tree

10 files changed

+365
-0
lines changed

10 files changed

+365
-0
lines changed

Math/Math.Lib/Math.Lib.csproj

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<PropertyGroup>
4+
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
5+
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
6+
<ProductVersion>8.0.30703</ProductVersion>
7+
<SchemaVersion>2.0</SchemaVersion>
8+
<ProjectGuid>{8B0938A8-8D54-4AD6-8717-3EC40291A67F}</ProjectGuid>
9+
<OutputType>Library</OutputType>
10+
<AppDesignerFolder>Properties</AppDesignerFolder>
11+
<RootNamespace>Math.Lib</RootNamespace>
12+
<AssemblyName>Math.Lib</AssemblyName>
13+
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
14+
<FileAlignment>512</FileAlignment>
15+
</PropertyGroup>
16+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
17+
<DebugSymbols>true</DebugSymbols>
18+
<DebugType>full</DebugType>
19+
<Optimize>false</Optimize>
20+
<OutputPath>bin\Debug\</OutputPath>
21+
<DefineConstants>DEBUG;TRACE</DefineConstants>
22+
<ErrorReport>prompt</ErrorReport>
23+
<WarningLevel>4</WarningLevel>
24+
</PropertyGroup>
25+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
26+
<DebugType>pdbonly</DebugType>
27+
<Optimize>true</Optimize>
28+
<OutputPath>bin\Release\</OutputPath>
29+
<DefineConstants>TRACE</DefineConstants>
30+
<ErrorReport>prompt</ErrorReport>
31+
<WarningLevel>4</WarningLevel>
32+
</PropertyGroup>
33+
<ItemGroup>
34+
<Reference Include="System" />
35+
<Reference Include="System.Core" />
36+
<Reference Include="System.Xml.Linq" />
37+
<Reference Include="System.Data.DataSetExtensions" />
38+
<Reference Include="Microsoft.CSharp" />
39+
<Reference Include="System.Data" />
40+
<Reference Include="System.Xml" />
41+
</ItemGroup>
42+
<ItemGroup>
43+
<Compile Include="MissingNumberSln.cs" />
44+
<Compile Include="PerfectNumberSln.cs" />
45+
<Compile Include="PowerOfTwoSln.cs" />
46+
<Compile Include="Properties\AssemblyInfo.cs" />
47+
</ItemGroup>
48+
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
49+
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
50+
Other similar extension points exist, see Microsoft.Common.targets.
51+
<Target Name="BeforeBuild">
52+
</Target>
53+
<Target Name="AfterBuild">
54+
</Target>
55+
-->
56+
</Project>

Math/Math.Lib/MissingNumberSln.cs

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/* ==============================================================================
2+
* 功能描述:MissingNumberSln
3+
* 创 建 者:gz
4+
* 创建日期:2017/4/28 19:00:44
5+
* ==============================================================================*/
6+
using System;
7+
using System.Collections.Generic;
8+
using System.Linq;
9+
using System.Text;
10+
11+
namespace Math.Lib
12+
{
13+
/// <summary>
14+
/// MissingNumberSln
15+
/// </summary>
16+
public class MissingNumberSln
17+
{
18+
//Given an array containing n distinct numbers taken from 0, 1, 2, ..., n, find the one that is missing from the array.
19+
//For example,
20+
//Given nums = [0, 1, 3] return 2.
21+
//Note:
22+
//Your algorithm should run in linear runtime complexity. Could you implement it using only constant extra space complexity?
23+
#region 公有方法
24+
25+
public class Solution
26+
{
27+
public int MissingNumber(int[] nums)
28+
{
29+
int xor = 0, i = 0;
30+
for (i = 0; i < nums.Length; i++)
31+
{
32+
xor = xor ^ i ^ nums[i];
33+
}
34+
//最后再和个数i异或,这样所有的索引与下标都异或了,找到缺失元素。
35+
return xor ^ i;
36+
}
37+
}
38+
39+
#endregion
40+
41+
}
42+
}

Math/Math.Lib/PerfectNumberSln.cs

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/* ==============================================================================
2+
* 功能描述:PerfectNumberSln
3+
* 创 建 者:gz
4+
* 创建日期:2017/4/28 19:08:01
5+
* ==============================================================================*/
6+
using System;
7+
using System.Collections.Generic;
8+
using System.Linq;
9+
using System.Text;
10+
11+
namespace Math.Lib
12+
{
13+
/// <summary>
14+
/// PerfectNumberSln
15+
/// </summary>
16+
public class PerfectNumberSln
17+
{
18+
19+
#region 公有方法
20+
// We define the Perfect Number is a positive integer that is equal to the sum of all its positive divisors except itself.
21+
22+
//Now, given an integer n, write a function that returns true when it is a perfect number and false when it is not.
23+
//Example:
24+
25+
//Input: 28
26+
//Output: True
27+
//Explanation: 28 = 1 + 2 + 4 + 7 + 14
28+
public bool CheckPerfectNumber(int num)
29+
{
30+
int sum = 1;
31+
int tmp = num;
32+
if (num == 0 || num == 1)//特别注意边界值
33+
return false;
34+
while (num % 2 == 0)
35+
{
36+
num /= 2;
37+
sum += num + tmp / num;
38+
}
39+
return sum == tmp;
40+
}
41+
42+
43+
#endregion
44+
45+
}
46+
}

Math/Math.Lib/PowerOfTwoSln.cs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/* ==============================================================================
2+
* 功能描述:PowerOfTwo
3+
* 创 建 者:gz
4+
* 创建日期:2017/4/28 18:58:49
5+
* ==============================================================================*/
6+
using System;
7+
using System.Collections.Generic;
8+
using System.Linq;
9+
using System.Text;
10+
11+
namespace Math.Lib
12+
{
13+
//Given an integer, write a function to determine if it is a power of two.
14+
/// <summary>
15+
/// PowerOfTwo
16+
/// </summary>
17+
public class PowerOfTwoSln
18+
{
19+
20+
#region 公有方法
21+
22+
public bool IsPowerOfTwo(int n)
23+
{
24+
if (n <= 0) return false;
25+
while (n > 1)
26+
{
27+
if (n % 2 > 0) return false;
28+
n /= 2;
29+
}
30+
return true;
31+
}
32+
33+
#endregion
34+
35+
}
36+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
using System.Reflection;
2+
using System.Runtime.CompilerServices;
3+
using System.Runtime.InteropServices;
4+
5+
// 有关程序集的常规信息通过以下
6+
// 特性集控制。更改这些特性值可修改
7+
// 与程序集关联的信息。
8+
[assembly: AssemblyTitle("Math.Lib")]
9+
[assembly: AssemblyDescription("")]
10+
[assembly: AssemblyConfiguration("")]
11+
[assembly: AssemblyCompany("")]
12+
[assembly: AssemblyProduct("Math.Lib")]
13+
[assembly: AssemblyCopyright("Copyright © 2017")]
14+
[assembly: AssemblyTrademark("")]
15+
[assembly: AssemblyCulture("")]
16+
17+
// 将 ComVisible 设置为 false 使此程序集中的类型
18+
// 对 COM 组件不可见。如果需要从 COM 访问此程序集中的类型,
19+
// 则将该类型上的 ComVisible 特性设置为 true。
20+
[assembly: ComVisible(false)]
21+
22+
// 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID
23+
[assembly: Guid("51570846-e420-4138-bb6d-0f88644a8c17")]
24+
25+
// 程序集的版本信息由下面四个值组成:
26+
//
27+
// 主版本
28+
// 次版本
29+
// 内部版本号
30+
// 修订号
31+
//
32+
// 可以指定所有这些值,也可以使用“内部版本号”和“修订号”的默认值,
33+
// 方法是按如下所示使用“*”:
34+
// [assembly: AssemblyVersion("1.0.*")]
35+
[assembly: AssemblyVersion("1.0.0.0")]
36+
[assembly: AssemblyFileVersion("1.0.0.0")]

Math/Math.sln

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 11.00
3+
# Visual Studio 2010
4+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Math", "Math\Math.csproj", "{DA0C3619-ACFD-4715-9193-20A258D42825}"
5+
EndProject
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Math.Lib", "Math.Lib\Math.Lib.csproj", "{8B0938A8-8D54-4AD6-8717-3EC40291A67F}"
7+
EndProject
8+
Global
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|Any CPU = Debug|Any CPU
11+
Debug|Mixed Platforms = Debug|Mixed Platforms
12+
Debug|x86 = Debug|x86
13+
Release|Any CPU = Release|Any CPU
14+
Release|Mixed Platforms = Release|Mixed Platforms
15+
Release|x86 = Release|x86
16+
EndGlobalSection
17+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
18+
{DA0C3619-ACFD-4715-9193-20A258D42825}.Debug|Any CPU.ActiveCfg = Debug|x86
19+
{DA0C3619-ACFD-4715-9193-20A258D42825}.Debug|Mixed Platforms.ActiveCfg = Debug|x86
20+
{DA0C3619-ACFD-4715-9193-20A258D42825}.Debug|Mixed Platforms.Build.0 = Debug|x86
21+
{DA0C3619-ACFD-4715-9193-20A258D42825}.Debug|x86.ActiveCfg = Debug|x86
22+
{DA0C3619-ACFD-4715-9193-20A258D42825}.Debug|x86.Build.0 = Debug|x86
23+
{DA0C3619-ACFD-4715-9193-20A258D42825}.Release|Any CPU.ActiveCfg = Release|x86
24+
{DA0C3619-ACFD-4715-9193-20A258D42825}.Release|Mixed Platforms.ActiveCfg = Release|x86
25+
{DA0C3619-ACFD-4715-9193-20A258D42825}.Release|Mixed Platforms.Build.0 = Release|x86
26+
{DA0C3619-ACFD-4715-9193-20A258D42825}.Release|x86.ActiveCfg = Release|x86
27+
{DA0C3619-ACFD-4715-9193-20A258D42825}.Release|x86.Build.0 = Release|x86
28+
{8B0938A8-8D54-4AD6-8717-3EC40291A67F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
29+
{8B0938A8-8D54-4AD6-8717-3EC40291A67F}.Debug|Any CPU.Build.0 = Debug|Any CPU
30+
{8B0938A8-8D54-4AD6-8717-3EC40291A67F}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
31+
{8B0938A8-8D54-4AD6-8717-3EC40291A67F}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
32+
{8B0938A8-8D54-4AD6-8717-3EC40291A67F}.Debug|x86.ActiveCfg = Debug|Any CPU
33+
{8B0938A8-8D54-4AD6-8717-3EC40291A67F}.Release|Any CPU.ActiveCfg = Release|Any CPU
34+
{8B0938A8-8D54-4AD6-8717-3EC40291A67F}.Release|Any CPU.Build.0 = Release|Any CPU
35+
{8B0938A8-8D54-4AD6-8717-3EC40291A67F}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
36+
{8B0938A8-8D54-4AD6-8717-3EC40291A67F}.Release|Mixed Platforms.Build.0 = Release|Any CPU
37+
{8B0938A8-8D54-4AD6-8717-3EC40291A67F}.Release|x86.ActiveCfg = Release|Any CPU
38+
EndGlobalSection
39+
GlobalSection(SolutionProperties) = preSolution
40+
HideSolutionNode = FALSE
41+
EndGlobalSection
42+
EndGlobal

Math/Math.suo

17 KB
Binary file not shown.

Math/Math/Math.csproj

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<PropertyGroup>
4+
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
5+
<Platform Condition=" '$(Platform)' == '' ">x86</Platform>
6+
<ProductVersion>8.0.30703</ProductVersion>
7+
<SchemaVersion>2.0</SchemaVersion>
8+
<ProjectGuid>{DA0C3619-ACFD-4715-9193-20A258D42825}</ProjectGuid>
9+
<OutputType>Exe</OutputType>
10+
<AppDesignerFolder>Properties</AppDesignerFolder>
11+
<RootNamespace>Math</RootNamespace>
12+
<AssemblyName>Math</AssemblyName>
13+
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
14+
<TargetFrameworkProfile>Client</TargetFrameworkProfile>
15+
<FileAlignment>512</FileAlignment>
16+
</PropertyGroup>
17+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
18+
<PlatformTarget>x86</PlatformTarget>
19+
<DebugSymbols>true</DebugSymbols>
20+
<DebugType>full</DebugType>
21+
<Optimize>false</Optimize>
22+
<OutputPath>bin\Debug\</OutputPath>
23+
<DefineConstants>DEBUG;TRACE</DefineConstants>
24+
<ErrorReport>prompt</ErrorReport>
25+
<WarningLevel>4</WarningLevel>
26+
</PropertyGroup>
27+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x86' ">
28+
<PlatformTarget>x86</PlatformTarget>
29+
<DebugType>pdbonly</DebugType>
30+
<Optimize>true</Optimize>
31+
<OutputPath>bin\Release\</OutputPath>
32+
<DefineConstants>TRACE</DefineConstants>
33+
<ErrorReport>prompt</ErrorReport>
34+
<WarningLevel>4</WarningLevel>
35+
</PropertyGroup>
36+
<ItemGroup>
37+
<Reference Include="System" />
38+
<Reference Include="System.Core" />
39+
<Reference Include="System.Xml.Linq" />
40+
<Reference Include="System.Data.DataSetExtensions" />
41+
<Reference Include="Microsoft.CSharp" />
42+
<Reference Include="System.Data" />
43+
<Reference Include="System.Xml" />
44+
</ItemGroup>
45+
<ItemGroup>
46+
<Compile Include="Program.cs" />
47+
<Compile Include="Properties\AssemblyInfo.cs" />
48+
</ItemGroup>
49+
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
50+
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
51+
Other similar extension points exist, see Microsoft.Common.targets.
52+
<Target Name="BeforeBuild">
53+
</Target>
54+
<Target Name="AfterBuild">
55+
</Target>
56+
-->
57+
</Project>

Math/Math/Program.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
6+
namespace Math
7+
{
8+
class Program
9+
{
10+
static void Main(string[] args)
11+
{
12+
}
13+
}
14+
}

Math/Math/Properties/AssemblyInfo.cs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
using System.Reflection;
2+
using System.Runtime.CompilerServices;
3+
using System.Runtime.InteropServices;
4+
5+
// 有关程序集的常规信息通过以下
6+
// 特性集控制。更改这些特性值可修改
7+
// 与程序集关联的信息。
8+
[assembly: AssemblyTitle("Math")]
9+
[assembly: AssemblyDescription("")]
10+
[assembly: AssemblyConfiguration("")]
11+
[assembly: AssemblyCompany("")]
12+
[assembly: AssemblyProduct("Math")]
13+
[assembly: AssemblyCopyright("Copyright © 2017")]
14+
[assembly: AssemblyTrademark("")]
15+
[assembly: AssemblyCulture("")]
16+
17+
// 将 ComVisible 设置为 false 使此程序集中的类型
18+
// 对 COM 组件不可见。如果需要从 COM 访问此程序集中的类型,
19+
// 则将该类型上的 ComVisible 特性设置为 true。
20+
[assembly: ComVisible(false)]
21+
22+
// 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID
23+
[assembly: Guid("0c6b6a7c-0e05-41a0-8f70-6d5ac1c84869")]
24+
25+
// 程序集的版本信息由下面四个值组成:
26+
//
27+
// 主版本
28+
// 次版本
29+
// 内部版本号
30+
// 修订号
31+
//
32+
// 可以指定所有这些值,也可以使用“内部版本号”和“修订号”的默认值,
33+
// 方法是按如下所示使用“*”:
34+
// [assembly: AssemblyVersion("1.0.*")]
35+
[assembly: AssemblyVersion("1.0.0.0")]
36+
[assembly: AssemblyFileVersion("1.0.0.0")]

0 commit comments

Comments
 (0)