mirror of
https://github.com/ikoHSE/KR1.git
synced 2024-11-22 02:53:47 +03:00
Initial commit
This commit is contained in:
parent
778d8f3786
commit
0077ad3668
15
KR.userprefs
Normal file
15
KR.userprefs
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
<Properties StartupConfiguration="{4C6DB024-2B7E-4F8B-A9EE-8D25899E11AC}|Default">
|
||||||
|
<MonoDevelop.Ide.Workbench ActiveDocument="KR/Program.cs">
|
||||||
|
<Files>
|
||||||
|
<File FileName="KR/Program.cs" Line="9" Column="26" />
|
||||||
|
<File FileName="KR/iko.cs" Line="40" Column="27" />
|
||||||
|
</Files>
|
||||||
|
</MonoDevelop.Ide.Workbench>
|
||||||
|
<MonoDevelop.Ide.Workspace ActiveConfiguration="Debug|x86" />
|
||||||
|
<MonoDevelop.Ide.DebuggingService.Breakpoints>
|
||||||
|
<BreakpointStore />
|
||||||
|
</MonoDevelop.Ide.DebuggingService.Breakpoints>
|
||||||
|
<MonoDevelop.Ide.DebuggingService.PinnedWatches />
|
||||||
|
<MonoDevelop.Ide.ItemProperties.KR PreferredExecutionTarget="MonoDevelop.Default" />
|
||||||
|
<MultiItemStartupConfigurations />
|
||||||
|
</Properties>
|
40
KR/KR1.csproj
Normal file
40
KR/KR1.csproj
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||||
|
<PropertyGroup>
|
||||||
|
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||||
|
<Platform Condition=" '$(Platform)' == '' ">x86</Platform>
|
||||||
|
<ProjectGuid>{4C6DB024-2B7E-4F8B-A9EE-8D25899E11AC}</ProjectGuid>
|
||||||
|
<OutputType>Exe</OutputType>
|
||||||
|
<RootNamespace>KR1</RootNamespace>
|
||||||
|
<AssemblyName>KR</AssemblyName>
|
||||||
|
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
|
||||||
|
</PropertyGroup>
|
||||||
|
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
|
||||||
|
<DebugSymbols>true</DebugSymbols>
|
||||||
|
<DebugType>full</DebugType>
|
||||||
|
<Optimize>false</Optimize>
|
||||||
|
<OutputPath>bin\Debug</OutputPath>
|
||||||
|
<DefineConstants>DEBUG;</DefineConstants>
|
||||||
|
<ErrorReport>prompt</ErrorReport>
|
||||||
|
<WarningLevel>4</WarningLevel>
|
||||||
|
<ExternalConsole>true</ExternalConsole>
|
||||||
|
<PlatformTarget>x86</PlatformTarget>
|
||||||
|
</PropertyGroup>
|
||||||
|
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x86' ">
|
||||||
|
<Optimize>true</Optimize>
|
||||||
|
<OutputPath>bin\Release</OutputPath>
|
||||||
|
<ErrorReport>prompt</ErrorReport>
|
||||||
|
<WarningLevel>4</WarningLevel>
|
||||||
|
<ExternalConsole>true</ExternalConsole>
|
||||||
|
<PlatformTarget>x86</PlatformTarget>
|
||||||
|
</PropertyGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<Reference Include="System" />
|
||||||
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<Compile Include="Program.cs" />
|
||||||
|
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||||
|
<Compile Include="iko.cs" />
|
||||||
|
</ItemGroup>
|
||||||
|
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
|
||||||
|
</Project>
|
104
KR/Program.cs
Normal file
104
KR/Program.cs
Normal file
@ -0,0 +1,104 @@
|
|||||||
|
/*
|
||||||
|
ФИО: Костюченко Илья Игоревич
|
||||||
|
Группа: БПИ 171-1
|
||||||
|
Дата: 17.10.17
|
||||||
|
Вариант: KRmod1.1
|
||||||
|
*/
|
||||||
|
|
||||||
|
using System;
|
||||||
|
using static Iko.Console;
|
||||||
|
using static System.Console;
|
||||||
|
|
||||||
|
/*
|
||||||
|
# Alternative solution 1
|
||||||
|
|
||||||
|
Instead of printing to the console and retrning a bool, ProcessNumber could return
|
||||||
|
an array of numbers, conforming to the passed predecate.
|
||||||
|
|
||||||
|
# Alternative solution 2
|
||||||
|
|
||||||
|
ProcessNumber could take just the number as a parameter and
|
||||||
|
return an array of tuples (<number of `0`>, <number of `1`>)
|
||||||
|
|
||||||
|
# Alternative solution 3
|
||||||
|
|
||||||
|
The number of `0` and `1` can also be counted by repeatedly dividing the given number by 2.
|
||||||
|
*/
|
||||||
|
|
||||||
|
class MainClass {
|
||||||
|
/// <summary>
|
||||||
|
/// Counts the number of charecters that are equal to the specified character in the binary string represenattion of the given number.
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>the number of characters</returns>
|
||||||
|
/// <param name="number">the number to be processed</param>
|
||||||
|
/// <param name="bit">the character represenation of the bit ti be counted</param>
|
||||||
|
static int CountBinary(int number, char bit) {
|
||||||
|
int outp = 0;
|
||||||
|
foreach (char character in Convert.ToString(number, 2)) {
|
||||||
|
if (character == bit) {
|
||||||
|
outp += 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return outp;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Counts the number of `1` in the binary represenation of the number
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>The number of `1` in the binary represenation of the number</returns>
|
||||||
|
/// <param name="number">The number to be processed</param>
|
||||||
|
static int CountBinaryOnes(int number) {
|
||||||
|
return CountBinary(number, '1');
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Counts the number of `0` in the binary represenation of the number
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>The number of `0` in the binary represenation of the number</returns>
|
||||||
|
/// <param name="number">The number to be processed</param>
|
||||||
|
static int CountBinaryZeros(int number) {
|
||||||
|
return CountBinary(number, '0');
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Prompts the user for a number in the range (0;10000) and returns the number.
|
||||||
|
/// If the number does not conform to the requirements, the user will be prompted again.
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>The number put in by the user</returns>
|
||||||
|
/// <param name="message">A string propmpting the user for input.</param>
|
||||||
|
/// <param name="errorMessage">A string telling the user, he didn't input correct data</param>
|
||||||
|
static int ReadNumber(string message, string errorMessage) {
|
||||||
|
return GetInt(message, x => x > 0 && x < 10000, errorMessage);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Outputs all numbers from the range (0; number], conforming to the passed function.
|
||||||
|
/// </summary>
|
||||||
|
/// <returns><c>true</c>, if number any number was output to the console, <c>false</c> otherwise.</returns>
|
||||||
|
/// <param name="number">The upper-bound of the range to be tested</param>
|
||||||
|
/// <param name="validate">The function used to test numbers</param>
|
||||||
|
static bool ProcessNumber(int number, Func<int, int, bool> validate) {
|
||||||
|
bool didSucceed = false;
|
||||||
|
for (int i = 1; i <= number; i++) {
|
||||||
|
if (validate(CountBinaryZeros(i), CountBinaryOnes(i))) {
|
||||||
|
didSucceed = true;
|
||||||
|
WriteLine(i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return didSucceed;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void Main(string[] args) {
|
||||||
|
Repeat(() => {
|
||||||
|
int number = ReadNumber($"Please enter a positive number smaller than 10000{Environment.NewLine}N = "
|
||||||
|
, "That is not a valid positive number smaller than 10000");
|
||||||
|
if (ProcessNumber(number, (a, b) => a == b)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (ProcessNumber(number, (a, b) => a + 1 == b)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
WriteLine("That number does not yield any results...");
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
26
KR/Properties/AssemblyInfo.cs
Normal file
26
KR/Properties/AssemblyInfo.cs
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
using System.Reflection;
|
||||||
|
using System.Runtime.CompilerServices;
|
||||||
|
|
||||||
|
// Information about this assembly is defined by the following attributes.
|
||||||
|
// Change them to the values specific to your project.
|
||||||
|
|
||||||
|
[assembly: AssemblyTitle("KR")]
|
||||||
|
[assembly: AssemblyDescription("")]
|
||||||
|
[assembly: AssemblyConfiguration("")]
|
||||||
|
[assembly: AssemblyCompany("")]
|
||||||
|
[assembly: AssemblyProduct("")]
|
||||||
|
[assembly: AssemblyCopyright("")]
|
||||||
|
[assembly: AssemblyTrademark("")]
|
||||||
|
[assembly: AssemblyCulture("")]
|
||||||
|
|
||||||
|
// The assembly version has the format "{Major}.{Minor}.{Build}.{Revision}".
|
||||||
|
// The form "{Major}.{Minor}.*" will automatically update the build and revision,
|
||||||
|
// and "{Major}.{Minor}.{Build}.*" will update just the revision.
|
||||||
|
|
||||||
|
[assembly: AssemblyVersion("1.0.*")]
|
||||||
|
|
||||||
|
// The following attributes are used to specify the signing key for the assembly,
|
||||||
|
// if desired. See the Mono documentation for more information about signing.
|
||||||
|
|
||||||
|
//[assembly: AssemblyDelaySign(false)]
|
||||||
|
//[assembly: AssemblyKeyFile("")]
|
BIN
KR/bin/Debug/KR.exe
Normal file
BIN
KR/bin/Debug/KR.exe
Normal file
Binary file not shown.
BIN
KR/bin/Debug/KR.pdb
Normal file
BIN
KR/bin/Debug/KR.pdb
Normal file
Binary file not shown.
64
KR/iko.cs
Normal file
64
KR/iko.cs
Normal file
@ -0,0 +1,64 @@
|
|||||||
|
using System;
|
||||||
|
using static System.Console;
|
||||||
|
|
||||||
|
namespace Iko {
|
||||||
|
static class Console {
|
||||||
|
public static double GetDouble(string text, Func<double, bool> validate, string falseText) {
|
||||||
|
Write(text);
|
||||||
|
double res;
|
||||||
|
while (true) {
|
||||||
|
if (double.TryParse(ReadLine(), out res) && validate(res)) {
|
||||||
|
return res;
|
||||||
|
} else {
|
||||||
|
WriteLine(falseText);
|
||||||
|
Write(text);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static double GetDouble(string text, string falseText) {
|
||||||
|
return GetDouble(text, _ => { return true; }, falseText);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static float GetFloat(string text, Func<float, bool> validate, string falseText) {
|
||||||
|
Write(text);
|
||||||
|
float res;
|
||||||
|
while (true) {
|
||||||
|
if (float.TryParse(ReadLine(), out res) && validate(res)) {
|
||||||
|
return res;
|
||||||
|
} else {
|
||||||
|
WriteLine(falseText);
|
||||||
|
Write(text);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static float GetFloat(string text, string falseText) {
|
||||||
|
return GetFloat(text, _ => { return true; }, falseText);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static int GetInt(string text, Func<int, bool> validate, string falseText) {
|
||||||
|
Write(text);
|
||||||
|
int res;
|
||||||
|
while (true) {
|
||||||
|
if (int.TryParse(ReadLine(), out res) && validate(res)) {
|
||||||
|
return res;
|
||||||
|
} else {
|
||||||
|
WriteLine(falseText);
|
||||||
|
Write(text);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static int GetInt(string text, string falseText) {
|
||||||
|
return GetInt(text, _ => { return true; }, falseText);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void Repeat(Action f) {
|
||||||
|
do {
|
||||||
|
f();
|
||||||
|
Write("Press Enter to repeat program. Press any other key to quit.");
|
||||||
|
} while (ReadKey().Key == ConsoleKey.Enter);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
1
KR/obj/x86/Debug/KR.csproj.CoreCompileInputs.cache
Normal file
1
KR/obj/x86/Debug/KR.csproj.CoreCompileInputs.cache
Normal file
@ -0,0 +1 @@
|
|||||||
|
62543f0b6aa88a2a527b88cae3a0aa492fa84e34
|
5
KR/obj/x86/Debug/KR.csproj.FileListAbsolute.txt
Normal file
5
KR/obj/x86/Debug/KR.csproj.FileListAbsolute.txt
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
/Users/ilya/Developer/HSE/KR/KR/bin/Debug/KR.exe
|
||||||
|
/Users/ilya/Developer/HSE/KR/KR/bin/Debug/KR.pdb
|
||||||
|
/Users/ilya/Developer/HSE/KR/KR/obj/x86/Debug/KR.csproj.CoreCompileInputs.cache
|
||||||
|
/Users/ilya/Developer/HSE/KR/KR/obj/x86/Debug/KR.exe
|
||||||
|
/Users/ilya/Developer/HSE/KR/KR/obj/x86/Debug/KR.pdb
|
BIN
KR/obj/x86/Debug/KR.exe
Normal file
BIN
KR/obj/x86/Debug/KR.exe
Normal file
Binary file not shown.
BIN
KR/obj/x86/Debug/KR.pdb
Normal file
BIN
KR/obj/x86/Debug/KR.pdb
Normal file
Binary file not shown.
1
KR/obj/x86/Debug/KR1.csproj.CoreCompileInputs.cache
Normal file
1
KR/obj/x86/Debug/KR1.csproj.CoreCompileInputs.cache
Normal file
@ -0,0 +1 @@
|
|||||||
|
8578ba116c5805ead7d11590607b3474c8cd2ea8
|
5
KR/obj/x86/Debug/KR1.csproj.FileListAbsolute.txt
Normal file
5
KR/obj/x86/Debug/KR1.csproj.FileListAbsolute.txt
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
/Users/ilya/Developer/HSE/KR1/KR/bin/Debug/KR.exe
|
||||||
|
/Users/ilya/Developer/HSE/KR1/KR/bin/Debug/KR.pdb
|
||||||
|
/Users/ilya/Developer/HSE/KR1/KR/obj/x86/Debug/KR1.csproj.CoreCompileInputs.cache
|
||||||
|
/Users/ilya/Developer/HSE/KR1/KR/obj/x86/Debug/KR.exe
|
||||||
|
/Users/ilya/Developer/HSE/KR1/KR/obj/x86/Debug/KR.pdb
|
17
KR1.sln
Normal file
17
KR1.sln
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
|
||||||
|
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||||
|
# Visual Studio 2012
|
||||||
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "KR1", "KR\KR1.csproj", "{4C6DB024-2B7E-4F8B-A9EE-8D25899E11AC}"
|
||||||
|
EndProject
|
||||||
|
Global
|
||||||
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
|
Debug|x86 = Debug|x86
|
||||||
|
Release|x86 = Release|x86
|
||||||
|
EndGlobalSection
|
||||||
|
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||||
|
{4C6DB024-2B7E-4F8B-A9EE-8D25899E11AC}.Debug|x86.ActiveCfg = Debug|x86
|
||||||
|
{4C6DB024-2B7E-4F8B-A9EE-8D25899E11AC}.Debug|x86.Build.0 = Debug|x86
|
||||||
|
{4C6DB024-2B7E-4F8B-A9EE-8D25899E11AC}.Release|x86.ActiveCfg = Release|x86
|
||||||
|
{4C6DB024-2B7E-4F8B-A9EE-8D25899E11AC}.Release|x86.Build.0 = Release|x86
|
||||||
|
EndGlobalSection
|
||||||
|
EndGlobal
|
14
KR1.userprefs
Normal file
14
KR1.userprefs
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
<Properties StartupConfiguration="{4C6DB024-2B7E-4F8B-A9EE-8D25899E11AC}|Default">
|
||||||
|
<MonoDevelop.Ide.Workbench ActiveDocument="KR/Program.cs">
|
||||||
|
<Files>
|
||||||
|
<File FileName="KR/Program.cs" Line="1" Column="1" />
|
||||||
|
</Files>
|
||||||
|
</MonoDevelop.Ide.Workbench>
|
||||||
|
<MonoDevelop.Ide.Workspace ActiveConfiguration="Debug|x86" />
|
||||||
|
<MonoDevelop.Ide.ItemProperties.KR1 PreferredExecutionTarget="MonoDevelop.Default" />
|
||||||
|
<MonoDevelop.Ide.DebuggingService.Breakpoints>
|
||||||
|
<BreakpointStore />
|
||||||
|
</MonoDevelop.Ide.DebuggingService.Breakpoints>
|
||||||
|
<MonoDevelop.Ide.DebuggingService.PinnedWatches />
|
||||||
|
<MultiItemStartupConfigurations />
|
||||||
|
</Properties>
|
Loading…
Reference in New Issue
Block a user