Лабораторная работа 1. Правки

This commit is contained in:
BoiledMilk123 2024-02-19 10:27:36 +04:00
parent a0a8eccb42
commit 70bbd74e9e
9 changed files with 815 additions and 49 deletions

View File

@ -34,13 +34,13 @@ public class DrawningElectricLocomotive
/// <summary> /// <summary>
/// Ширина прорисовки электровоза /// Ширина прорисовки электровоза
/// </summary> /// </summary>
private readonly int _drawningElectricLocomotiveWidth = 100; private readonly int _drawningElectricLocomotiveWidth = 83;
/// <summary> /// <summary>
/// Высота прорисовки электровоза /// Высота прорисовки электровоза
/// </summary> /// </summary>
private readonly int _drawingElectricLocomotiveHeight = 45; private readonly int _drawningElectricLocomotiveHeight = 45;
/// <summary> /// <summary>
/// Инициализация свойств /// Инициализация свойств
@ -71,13 +71,19 @@ public class DrawningElectricLocomotive
/// <returns>true - границы заданы, false - проверка не пройдена, нельзя разместить объект в этих размерах</returns> /// <returns>true - границы заданы, false - проверка не пройдена, нельзя разместить объект в этих размерах</returns>
public bool SetPictureSize(int width, int height) public bool SetPictureSize(int width, int height)
{ {
// Проверка, что объект "влезает" в размеры поля if(_drawningElectricLocomotiveHeight > height || _drawningElectricLocomotiveWidth > width)
// если влезает, сохраняем границы и корректируем позицию объекта, если она была уже установлена
if(_drawingElectricLocomotiveHeight > height || _drawningElectricLocomotiveWidth > width)
{ {
return false; return false;
} }
if(_startPosY.HasValue && _startPosY - _drawningElectricLocomotiveHeight < _pictureHeight )
{
_startPosY -= _drawningElectricLocomotiveHeight;
}
if (_startPosX.HasValue && _startPosX - _drawningElectricLocomotiveWidth < _pictureWidth )
{
_startPosX -= _drawningElectricLocomotiveWidth;
}
_pictureWidth = width; _pictureWidth = width;
_pictureHeight = height; _pictureHeight = height;
return true; return true;
@ -94,17 +100,30 @@ public class DrawningElectricLocomotive
return; return;
} }
if (_drawingElectricLocomotiveHeight + y > _pictureHeight || _drawningElectricLocomotiveWidth + x > _pictureWidth)
_startPosX = x;
_startPosY = y;
if ( _drawningElectricLocomotiveHeight + y > _pictureHeight)
{
_startPosY = _pictureHeight - _drawningElectricLocomotiveHeight;
}
if ( _drawningElectricLocomotiveWidth + x > _pictureWidth)
{
_startPosX = _pictureWidth - _drawningElectricLocomotiveWidth;
}
if (x < 0)
{ {
_startPosX = 0; _startPosX = 0;
_startPosY = 0;
} }
else if (y < 0)
{ {
_startPosX = x; _startPosY = 0;
_startPosY = y;
} }
} }
/// <summary> /// <summary>
@ -123,14 +142,14 @@ public class DrawningElectricLocomotive
{ {
//влево //влево
case DirectionType.Left: case DirectionType.Left:
if(_startPosX.Value - EntityElectricLocomotive.Step + 20 > 0) if(_startPosX.Value - EntityElectricLocomotive.Step > 0)
{ {
_startPosX -= (int)EntityElectricLocomotive.Step; _startPosX -= (int)EntityElectricLocomotive.Step;
} }
return true; return true;
//вверх //вверх
case DirectionType.Up: case DirectionType.Up:
if(_startPosY.Value - EntityElectricLocomotive.Step + 3 > 0) if(_startPosY.Value - EntityElectricLocomotive.Step > 0)
{ {
_startPosY -= (int)EntityElectricLocomotive.Step; _startPosY -= (int)EntityElectricLocomotive.Step;
} }
@ -144,7 +163,7 @@ public class DrawningElectricLocomotive
return true; return true;
//вниз //вниз
case DirectionType.Down: case DirectionType.Down:
if (_startPosY.Value + _drawingElectricLocomotiveHeight + EntityElectricLocomotive.Step < _pictureHeight) if (_startPosY.Value + _drawningElectricLocomotiveHeight + EntityElectricLocomotive.Step < _pictureHeight)
{ {
_startPosY += (int)EntityElectricLocomotive.Step; _startPosY += (int)EntityElectricLocomotive.Step;
} }
@ -175,31 +194,31 @@ public class DrawningElectricLocomotive
Brush whiteBrush = new SolidBrush(Color.White); Brush whiteBrush = new SolidBrush(Color.White);
//Инициализация опорных точек для прорисовки корпуса //Инициализация опорных точек для прорисовки корпуса
Point pointStart = new Point(_startPosX.Value + 90, _startPosY.Value + 20); Point pointStart = new Point(_startPosX.Value + 75, _startPosY.Value + 20);
Point point1 = new Point(_startPosX.Value + 90, _startPosY.Value + 5); Point point1 = new Point(_startPosX.Value + 75, _startPosY.Value + 5);
Point point2 = new Point(_startPosX.Value + 25, _startPosY.Value + 5); Point point2 = new Point(_startPosX.Value + 10, _startPosY.Value + 5);
Point pointFinish = new Point(_startPosX.Value + 20, _startPosY.Value + 20); Point pointFinish = new Point(_startPosX.Value + 5, _startPosY.Value + 20);
//Инициализация опорных точек для прорисовки первой "юбки" //Инициализация опорных точек для прорисовки первой "юбки"
Point point3 = new Point(_startPosX.Value + 22, _startPosY.Value + 37); Point point3 = new Point(_startPosX.Value + 7, _startPosY.Value + 37);
Point point4 = new Point(_startPosX.Value + 15, _startPosY.Value + 37 +6 ); Point point4 = new Point(_startPosX.Value + 0, _startPosY.Value + 37 +6 );
Point point5 = new Point(_startPosX.Value + 22, _startPosY.Value + 37 + 6 ); Point point5 = new Point(_startPosX.Value + 7, _startPosY.Value + 37 + 6 );
//Инициализация опорных точек для прорисовки второй "юбки" //Инициализация опорных точек для прорисовки второй "юбки"
Point point6 = new Point(_startPosX.Value + 84, _startPosY.Value + 37); Point point6 = new Point(_startPosX.Value + 69, _startPosY.Value + 37);
Point point7 = new Point(_startPosX.Value + 90 + 7, _startPosY.Value + 37 + 6); Point point7 = new Point(_startPosX.Value + 75 + 7, _startPosY.Value + 37 + 6);
Point point8 = new Point(_startPosX.Value + 84, _startPosY.Value + 37 + 6); Point point8 = new Point(_startPosX.Value + 69, _startPosY.Value + 37 + 6);
//Инициализация опорных точек для прорисовки "рогов" //Инициализация опорных точек для прорисовки "рогов"
Point pointHorns1 = new Point(_startPosX.Value + 28, _startPosY.Value+5); Point pointHorns1 = new Point(_startPosX.Value + 13, _startPosY.Value+5);
Point pointHorns2 = new Point(_startPosX.Value + 31, _startPosY.Value + 2); Point pointHorns2 = new Point(_startPosX.Value + 16, _startPosY.Value + 2);
Point pointHorns3 = new Point(_startPosX.Value + 26, _startPosY.Value); Point pointHorns3 = new Point(_startPosX.Value + 11, _startPosY.Value);
//Инициализация опорных точек для прорисовки молнии на хранилище батарей //Инициализация опорных точек для прорисовки молнии на хранилище батарей
Point pointLightning1 = new Point(_startPosX.Value + 54, _startPosY.Value + 37); Point pointLightning1 = new Point(_startPosX.Value + 39, _startPosY.Value + 37);
Point pointLightning2 = new Point(_startPosX.Value + 52, _startPosY.Value + 39); Point pointLightning2 = new Point(_startPosX.Value + 37, _startPosY.Value + 39);
Point pointLightning3 = new Point(_startPosX.Value + 54, _startPosY.Value + 40); Point pointLightning3 = new Point(_startPosX.Value + 39, _startPosY.Value + 40);
Point pointLightning4 = new Point(_startPosX.Value + 52, _startPosY.Value + 41); Point pointLightning4 = new Point(_startPosX.Value + 37, _startPosY.Value + 41);
//Совокупность точек полигона уголка первой "юбки" //Совокупность точек полигона уголка первой "юбки"
Point[] firstTrianglePoints = Point[] firstTrianglePoints =
@ -225,7 +244,7 @@ public class DrawningElectricLocomotive
g.FillPolygon(blackBrush, secondTrianglePoints); g.FillPolygon(blackBrush, secondTrianglePoints);
//Прорисовка корпуса //Прорисовка корпуса
g.DrawRectangle(pen, _startPosX.Value + 20, _startPosY.Value + 20, 70, 17); g.DrawRectangle(pen, _startPosX.Value + 5, _startPosY.Value + 20, 70, 17);
g.DrawLine(pen, point3, point4); g.DrawLine(pen, point3, point4);
g.DrawLine(pen, pointStart, point1); g.DrawLine(pen, pointStart, point1);
@ -235,41 +254,41 @@ public class DrawningElectricLocomotive
//Прорисовка передней и задней "юбки" //Прорисовка передней и задней "юбки"
g.FillRectangle(blackBrush, _startPosX.Value + 22, _startPosY.Value + 37, 25, 5.3f); g.FillRectangle(blackBrush, _startPosX.Value + 7, _startPosY.Value + 37, 25, 5.3f);
g.FillRectangle(blackBrush, _startPosX.Value + 62, _startPosY.Value + 37, 22, 5.3f); g.FillRectangle(blackBrush, _startPosX.Value + 47, _startPosY.Value + 37, 22, 5.3f);
//Прорисовка двух передних колёс //Прорисовка двух передних колёс
g.FillEllipse(whiteBrush, _startPosX.Value + 21.3f, _startPosY.Value + 37, 10, 10); g.FillEllipse(whiteBrush, _startPosX.Value + 6.3f, _startPosY.Value + 37, 10, 10);
g.DrawEllipse(penSolid, _startPosX.Value + 9, _startPosY.Value + 37, 8, 8);
g.FillEllipse(additionalBrush, _startPosX.Value + 9, _startPosY.Value + 37, 8, 8);
g.DrawEllipse(penSolid, _startPosX.Value + 24, _startPosY.Value + 37, 8, 8); g.DrawEllipse(penSolid, _startPosX.Value + 24, _startPosY.Value + 37, 8, 8);
g.FillEllipse(additionalBrush, _startPosX.Value + 24, _startPosY.Value + 37, 8, 8); g.FillEllipse(additionalBrush, _startPosX.Value + 24, _startPosY.Value + 37, 8, 8);
g.DrawEllipse(penSolid, _startPosX.Value + 39, _startPosY.Value + 37, 8, 8);
g.FillEllipse(additionalBrush, _startPosX.Value + 39, _startPosY.Value + 37, 8, 8);
//Прорисовка "рогов" электровоза //Прорисовка "рогов" электровоза
g.DrawLine(penSolid, pointHorns1, pointHorns2); g.DrawLine(penSolid, pointHorns1, pointHorns2);
g.DrawLine(penSolid, pointHorns2, pointHorns3); g.DrawLine(penSolid, pointHorns2, pointHorns3);
//Прорисовка "хранилища батарей" электровоза //Прорисовка "хранилища батарей" электровоза
g.FillRectangle(blackBrush, _startPosX.Value + 51, _startPosY.Value + 37, 8, 4.5f); g.FillRectangle(blackBrush, _startPosX.Value + 36, _startPosY.Value + 37, 8, 4.5f);
g.DrawLine(penSolidYellow, pointLightning1, pointLightning2); g.DrawLine(penSolidYellow, pointLightning1, pointLightning2);
g.DrawLine(penSolidYellow, pointLightning2, pointLightning3); g.DrawLine(penSolidYellow, pointLightning2, pointLightning3);
g.DrawLine(penSolidYellow, pointLightning3, pointLightning4); g.DrawLine(penSolidYellow, pointLightning3, pointLightning4);
//Прорисовка двух задних колёс //Прорисовка двух задних колёс
g.FillEllipse(whiteBrush, _startPosX.Value + 40 + 38, _startPosY.Value + 37, 10, 10); g.FillEllipse(whiteBrush, _startPosX.Value + 25 + 38, _startPosY.Value + 37, 10, 10);
g.DrawEllipse(penSolid, _startPosX.Value + 40 + 26, _startPosY.Value + 37, 8, 8); g.DrawEllipse(penSolid, _startPosX.Value + 25 + 26, _startPosY.Value + 37, 8, 8);
g.FillEllipse(additionalBrush, _startPosX.Value + 40 + 26, _startPosY.Value + 37, 8, 8); g.FillEllipse(additionalBrush, _startPosX.Value + 25 + 26, _startPosY.Value + 37, 8, 8);
g.DrawEllipse(penSolid, _startPosX.Value+ 40 + 37, _startPosY.Value + 37, 8, 8); g.DrawEllipse(penSolid, _startPosX.Value+ 25 + 37, _startPosY.Value + 37, 8, 8);
g.FillEllipse(additionalBrush, _startPosX.Value + 40 + 37, _startPosY.Value + 37, 8, 8); g.FillEllipse(additionalBrush, _startPosX.Value + 25 + 37, _startPosY.Value + 37, 8, 8);
//Прорисовка заднего "шлюза" //Прорисовка заднего "шлюза"
g.FillRectangle(blackBrush, _startPosX.Value + 90, _startPosY.Value + 9, 5.7f, 27.4f); g.FillRectangle(blackBrush, _startPosX.Value + 75, _startPosY.Value + 9, 5.7f, 27.4f);
//Прорисовка первого и третьего окна //Прорисовка первого и третьего окна
g.DrawRectangle(windowPen, _startPosX.Value + 27, _startPosY.Value + 9, 8, 8); g.DrawRectangle(windowPen, _startPosX.Value + 12, _startPosY.Value + 9, 8, 8);
g.DrawRectangle(windowPen, _startPosX.Value + 78, _startPosY.Value + 9, 8, 8); g.DrawRectangle(windowPen, _startPosX.Value + 63, _startPosY.Value + 9, 8, 8);
//TODO Опциональная прорисовка колёс для усложненной работы //TODO Опциональная прорисовка колёс для усложненной работы
@ -294,11 +313,11 @@ public class DrawningElectricLocomotive
if (EntityElectricLocomotive.BodyKit) if (EntityElectricLocomotive.BodyKit)
{ {
Brush brWhite = new SolidBrush(Color.White); Brush brWhite = new SolidBrush(Color.White);
g.DrawRectangle(windowPen, _startPosX.Value + 39.3f, _startPosY.Value + 9, 8, 8); g.DrawRectangle(windowPen, _startPosX.Value + 24.3f, _startPosY.Value + 9, 8, 8);
g.DrawRectangle(pen, _startPosX.Value + 50, _startPosY.Value + 14, 8, 12); g.DrawRectangle(pen, _startPosX.Value + 35, _startPosY.Value + 14, 8, 12);
g.FillRectangle(brWhite, _startPosX.Value + 51, _startPosY.Value + 16, 7, 10); g.FillRectangle(brWhite, _startPosX.Value + 36, _startPosY.Value + 16, 7, 10);
} }
} }

31
cfdiv3/cfdiv3.sln Normal file
View File

@ -0,0 +1,31 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.7.34024.191
MinimumVisualStudioVersion = 10.0.40219.1
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "cfdiv3", "cfdiv3\cfdiv3.vcxproj", "{A580EAEA-AEBB-4210-8DFA-E3E1241D9FCF}"
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
{A580EAEA-AEBB-4210-8DFA-E3E1241D9FCF}.Debug|x64.ActiveCfg = Debug|x64
{A580EAEA-AEBB-4210-8DFA-E3E1241D9FCF}.Debug|x64.Build.0 = Debug|x64
{A580EAEA-AEBB-4210-8DFA-E3E1241D9FCF}.Debug|x86.ActiveCfg = Debug|Win32
{A580EAEA-AEBB-4210-8DFA-E3E1241D9FCF}.Debug|x86.Build.0 = Debug|Win32
{A580EAEA-AEBB-4210-8DFA-E3E1241D9FCF}.Release|x64.ActiveCfg = Release|x64
{A580EAEA-AEBB-4210-8DFA-E3E1241D9FCF}.Release|x64.Build.0 = Release|x64
{A580EAEA-AEBB-4210-8DFA-E3E1241D9FCF}.Release|x86.ActiveCfg = Release|Win32
{A580EAEA-AEBB-4210-8DFA-E3E1241D9FCF}.Release|x86.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {C6324E34-5959-487B-98C6-891D3D3A1B32}
EndGlobalSection
EndGlobal

70
cfdiv3/cfdiv3/A.cpp Normal file
View File

@ -0,0 +1,70 @@
#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cstdio>
#include <stack>
#include <vector>
#include <iomanip>
#include <algorithm>
#include <string>
#include <cmath>
#include <queue>
#include <set>
#include <map>
#include <math.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<long long, long long> pll;
typedef pair<int, int> pii;
const ll LINF = 100098809990;
const int INF = 1009000999;
const int N = 1002;
const ld PI = 3.1415926535;
const ld E = 2.7182818284;
const ll MOD = 1000000007;
const int MAX = 150010;
ll solve(vector<ll>v, ll n) {
ll time = v[0]-1, k = 0;
for (int j = 0; j < n; j++) {
for (int i = time + 1; i < 10e10; i++) {
if (i % v[j] == 0) {
k += 1;
time = i;
if (k == n) {
return i;
}
break;
}
}
}
}
int main() {
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
ll t, n, zn, f = 0;
cin >> t;
for (int i = 0; i < t; i++) {
cin >> n;
vector<ll>v;
for (int j = 0; j < n; j++) {
cin >> zn;
v.push_back(zn);
}
f = solve(v, n);
cout << f << '\n';
}
return 0;
}

View File

@ -0,0 +1,135 @@
<?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>17.0</VCProjectVersion>
<Keyword>Win32Proj</Keyword>
<ProjectGuid>{a580eaea-aebb-4210-8dfa-e3e1241d9fcf}</ProjectGuid>
<RootNamespace>cfdiv3</RootNamespace>
<WindowsTargetPlatformVersion>10.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>v143</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v143</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v143</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v143</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" />
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="A.cpp" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>

View File

@ -0,0 +1,22 @@
<?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="A.cpp">
<Filter>Исходные файлы</Filter>
</ClCompile>
</ItemGroup>
</Project>

31
lab_aisd/lab_aisd.sln Normal file
View File

@ -0,0 +1,31 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.7.34024.191
MinimumVisualStudioVersion = 10.0.40219.1
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "lab_aisd", "lab_aisd\lab_aisd.vcxproj", "{DD05AB56-9070-4CED-A979-38A2FBA74B9A}"
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
{DD05AB56-9070-4CED-A979-38A2FBA74B9A}.Debug|x64.ActiveCfg = Debug|x64
{DD05AB56-9070-4CED-A979-38A2FBA74B9A}.Debug|x64.Build.0 = Debug|x64
{DD05AB56-9070-4CED-A979-38A2FBA74B9A}.Debug|x86.ActiveCfg = Debug|Win32
{DD05AB56-9070-4CED-A979-38A2FBA74B9A}.Debug|x86.Build.0 = Debug|Win32
{DD05AB56-9070-4CED-A979-38A2FBA74B9A}.Release|x64.ActiveCfg = Release|x64
{DD05AB56-9070-4CED-A979-38A2FBA74B9A}.Release|x64.Build.0 = Release|x64
{DD05AB56-9070-4CED-A979-38A2FBA74B9A}.Release|x86.ActiveCfg = Release|Win32
{DD05AB56-9070-4CED-A979-38A2FBA74B9A}.Release|x86.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {B1FBCA36-B401-40B8-BC85-D0E8E011D3C8}
EndGlobalSection
EndGlobal

301
lab_aisd/lab_aisd/lab1.cpp Normal file
View File

@ -0,0 +1,301 @@
#include <iostream>
#include <string>
using namespace std;
#define SIZE 100
struct Students {
string name;
int course_number;
string faculty;
};
struct Stack {
public:
struct Node
{
public:
Students data;
Node* next;
Node(Students data)
{
this->data = data;
this->next = nullptr;
}
};
private:
Node* head;
int size;
public:
Stack()
{
head = nullptr;
size = 0;
}
int length()
{
return size;
}
void push(Students data)
{
Node* temp = new Node(data);
temp->next = head;
head = temp;
size++;
}
Students top()
{
if (head == nullptr) exit(0);
return head->data;
}
void pop()
{
if (head == nullptr) return;
Node* ptr = head->next;
delete head;
head = ptr;
size--;
}
bool isEmpty()
{
return size != 0;
}
void print()
{
if (head == nullptr) return;
Node* ptr = head;
while(true)
{
cout << "Name = " << ptr->data.name << "\t";
cout << "Course number = " << ptr->data.course_number << "\t";
cout << "Faculty = " << ptr->data.faculty << "\n";
if (ptr->next == nullptr) break;
ptr = ptr->next;
}
}
void erase()
{
if (head == nullptr) return;
Node* ptr = head;
while (ptr->next != nullptr)
{
head = ptr;
ptr = ptr->next;
delete head;
}
head = nullptr;
size = 0;
}
Node* begin()
{
return head;
}
};
void merge(int arr[], int left[], int left_size, int right[], int right_size)
{
int i = 0, j = 0, k = 0;
while (i < left_size && j < right_size)
{
if (left[i] < right[j])
{
arr[k] = left[i];
i++;
}
else
{
arr[k] = right[j];
j++;
}
k++;
}
while (i < left_size)
{
arr[k] = left[i];
i++;
k++;
}
while (j < right_size)
{
arr[k] = right[j];
j++;
k++;
}
}
void merge(Stack& stack, Stack& left, Stack& right)
{
while (left.isEmpty() && right.isEmpty()) {
if (left.top().name < right.top().name)
{
stack.push(left.top());
left.pop();
}
else
{
stack.push(right.top());
right.pop();
}
}
while(left.isEmpty())
{
stack.push(left.top());
left.pop();
}
while (right.isEmpty())
{
stack.push(right.top());
right.pop();
}
}
void divide(Stack& stack) {
if (stack.length() <= 1) {
return;
}
int divide_to = (stack.length() % 2 == 0) ? stack.length() / 2 : stack.length() / 2 + 1;
Stack stackLeft, stackRight;
for (int i = 0; i < stack.length(); i++)
{
if (i < divide_to)
{
stackLeft.push(stack.top());
stack.pop();
}
else
{
stackRight.push(stack.top());
stack.pop();
}
}
divide(stackLeft);
divide(stackRight);
merge(stack, stackLeft, stackRight);
}
void divide(int arr[], int size)
{
if (size <= 1)
{
return;
}
int divide_to = (size % 2 == 0) ? size/2 : size / 2 + 1;
int left[SIZE];
int right[SIZE];
for (int i = 0; i < size; ++i)
{
if (i < divide_to) left[i] = arr[i];
else right[i - divide_to] = arr[i];
}
divide(left, divide_to);
divide(right, size - divide_to);
merge(arr, left, divide_to, right, size - divide_to);
}
void ShakingSort(int arr[]) {
int control = SIZE - 1;
int left = 0, right = control;
do {
for (int i = left; i < right; i++) {
if (arr[i] > arr[i + 1]) {
swap(arr[i], arr[i + 1]);
control = i;
}
}
right = control;
for (int i = right; i > left; i--) {
if (arr[i] < arr[i - 1]) {
swap(arr[i], arr[i - 1]);
control = i;
}
}
left = control;
} while (left < right);
}
void bubbleSort(Stack& stack)
{
int swapped, i;
Stack::Node* ptr;
Stack::Node* lptr = nullptr;
if (stack.begin() == nullptr)
return;
do
{
swapped = 0;
ptr = stack.begin();
while (ptr->next != lptr)
{
if (ptr->data.name > ptr->next->data.name)
{
swap(ptr->data, ptr->next->data);
swapped = 1;
}
ptr = ptr->next;
}
lptr = ptr;
} while (swapped);
}
int main()
{
Stack Test;
if (Test.isEmpty()) cout << "Stack is empty\n";
Students student1;
student1.course_number = 4;
student1.faculty = "FIST";
student1.name = "Aleksey Romanov";
Test.push(student1);
Students student2;
student2.course_number = 1;
student2.faculty = "IATU";
student2.name = "Danila Bugrov";
Test.push(student2);
Students student3;
student3.course_number = 3;
student3.faculty = "RTF";
student3.name = "Roman Ivanov";
Test.push(student3);
Students student4;
student4.course_number = 2;
student4.faculty = "RTF";
student4.name = "Ivan Aleksandrov";
Test.push(student4);
Test.print();
//Test.erase();
bubbleSort(Test);
cout << '\n';
Test.print();
/*int arr[SIZE];
for (auto& e : arr) e = rand() % SIZE;
for (auto& e : arr) cout << e << " ";
cout << '\n';
ShakingSort(arr);
for (auto& e : arr) cout << e << " ";
cout << '\n';*/
}

View File

@ -0,0 +1,135 @@
<?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>17.0</VCProjectVersion>
<Keyword>Win32Proj</Keyword>
<ProjectGuid>{dd05ab56-9070-4ced-a979-38a2fba74b9a}</ProjectGuid>
<RootNamespace>labaisd</RootNamespace>
<WindowsTargetPlatformVersion>10.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>v143</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v143</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v143</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v143</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" />
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="lab1.cpp" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>

View File

@ -0,0 +1,22 @@
<?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="lab1.cpp">
<Filter>Исходные файлы</Filter>
</ClCompile>
</ItemGroup>
</Project>