Initial commit
This commit is contained in:
10
cs3/C_Sharp_3_3/C_Sharp_3_3.csproj
Normal file
10
cs3/C_Sharp_3_3/C_Sharp_3_3.csproj
Normal file
@@ -0,0 +1,10 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
</Project>
|
||||
25
cs3/C_Sharp_3_3/C_Sharp_3_3.sln
Normal file
25
cs3/C_Sharp_3_3/C_Sharp_3_3.sln
Normal file
@@ -0,0 +1,25 @@
|
||||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio Version 17
|
||||
VisualStudioVersion = 17.14.36616.10 d17.14
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "C_Sharp_3_3", "C_Sharp_3_3.csproj", "{C1F468F9-1857-4917-A157-4DE92BC3AD2A}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
Release|Any CPU = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{C1F468F9-1857-4917-A157-4DE92BC3AD2A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{C1F468F9-1857-4917-A157-4DE92BC3AD2A}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{C1F468F9-1857-4917-A157-4DE92BC3AD2A}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{C1F468F9-1857-4917-A157-4DE92BC3AD2A}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||
SolutionGuid = {97BE73A5-1856-439E-85C5-BB65BF1F0541}
|
||||
EndGlobalSection
|
||||
EndGlobal
|
||||
46
cs3/C_Sharp_3_3/Program.cs
Normal file
46
cs3/C_Sharp_3_3/Program.cs
Normal file
@@ -0,0 +1,46 @@
|
||||
namespace C_Sharp_3_3
|
||||
{
|
||||
public class Program
|
||||
{
|
||||
static void Main(string[] args)
|
||||
{
|
||||
int c, r;
|
||||
Console.Write("请输入总只数");
|
||||
int h = int.Parse(Console.ReadLine());
|
||||
int f = 1;
|
||||
while (f % 2 != 0)
|
||||
{
|
||||
Console.Write("请输入总脚数(必须是偶数)");
|
||||
f = int.Parse(Console.ReadLine());
|
||||
}
|
||||
// 循环
|
||||
bool solution = false;
|
||||
for (c = 0; c <= h; c++)
|
||||
{
|
||||
r = h - c;
|
||||
if (2 * c + 4 * r == f)
|
||||
{
|
||||
Console.WriteLine("方法一:鸡有{0}只,兔有{1}只", c, r);
|
||||
solution = true;
|
||||
}
|
||||
}
|
||||
if (!solution)
|
||||
{
|
||||
Console.WriteLine("方法一无解");
|
||||
}
|
||||
// 解方程
|
||||
r = f / 2 - h;
|
||||
c = h - r;
|
||||
solution = false;
|
||||
if (c >= 0 && r >= 0)
|
||||
{
|
||||
Console.WriteLine("方法二:鸡有{0}只,兔有{1}只", c, r);
|
||||
solution = true;
|
||||
}
|
||||
if (!solution)
|
||||
{
|
||||
Console.WriteLine("方法二无解");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user