diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..35d4ccd --- /dev/null +++ b/.gitignore @@ -0,0 +1,206 @@ +# Download this file using PowerShell v3 under Windows with the following comand: +# Invoke-WebRequest https://gist.githubusercontent.com/kmorcinek/2710267/raw/ -OutFile .gitignore +# or wget: +# wget --no-check-certificate http://gist.githubusercontent.com/kmorcinek/2710267/raw/.gitignore + +# User-specific files +*.suo +*.user +*.sln.docstates + +# Build results + +[Dd]ebug/ +[Rr]elease/ +x64/ +build/ +[Bb]in/ +[Oo]bj/ + +# NuGet Packages +*.nupkg +# The packages folder can be ignored because of Package Restore +**/packages/* +# except build/, which is used as an MSBuild target. +!**/packages/build/ +# Uncomment if necessary however generally it will be regenerated when needed +#!**/packages/repositories.config + +# MSTest test Results +[Tt]est[Rr]esult*/ +[Bb]uild[Ll]og.* + +*_i.c +*_p.c +*.ilk +*.meta +*.obj +*.pch +*.pdb +*.pgc +*.pgd +*.rsp +*.sbr +*.tlb +*.tli +*.tlh +*.tmp +*.tmp_proj +*.log +*.vspscc +*.vssscc +.builds +*.pidb +*.log +*.scc + +# OS generated files # +.DS_Store* +Icon? + +# Visual C++ cache files +ipch/ +*.aps +*.ncb +*.opensdf +*.sdf +*.cachefile + +# Visual Studio profiler +*.psess +*.vsp +*.vspx + +# Guidance Automation Toolkit +*.gpState + +# ReSharper is a .NET coding add-in +_ReSharper*/ +*.[Rr]e[Ss]harper + +# TeamCity is a build add-in +_TeamCity* + +# DotCover is a Code Coverage Tool +*.dotCover + +# NCrunch +*.ncrunch* +.*crunch*.local.xml + +# Installshield output folder +[Ee]xpress/ + +# DocProject is a documentation generator add-in +DocProject/buildhelp/ +DocProject/Help/*.HxT +DocProject/Help/*.HxC +DocProject/Help/*.hhc +DocProject/Help/*.hhk +DocProject/Help/*.hhp +DocProject/Help/Html2 +DocProject/Help/html + +# Click-Once directory +publish/ + +# Publish Web Output +*.Publish.xml + +# Windows Azure Build Output +csx +*.build.csdef + +# Windows Store app package directory +AppPackages/ + +# Others +*.Cache +ClientBin/ +# [Ss]tyle[Cc]op.* +~$* +*~ +*.dbmdl +*.[Pp]ublish.xml +*.pfx +*.publishsettings +modulesbin/ +tempbin/ + +# EPiServer Site file (VPP) +AppData/ + +# RIA/Silverlight projects +Generated_Code/ + +# Backup & report files from converting an old project file to a newer +# Visual Studio version. Backup files are not needed, because we have git ;-) +_UpgradeReport_Files/ +Backup*/ +UpgradeLog*.XML +UpgradeLog*.htm + +# vim +*.txt~ +*.swp +*.swo + +# svn +.svn + +# Remainings from resolvings conflicts in Source Control +*.orig + +# SQL Server files +**/App_Data/*.mdf +**/App_Data/*.ldf +**/App_Data/*.sdf + + +#LightSwitch generated files +GeneratedArtifacts/ +_Pvt_Extensions/ +ModelManifest.xml + +# ========================= +# Windows detritus +# ========================= + +# Windows image file caches +Thumbs.db +ehthumbs.db + +# Folder config file +Desktop.ini + +# Recycle Bin used on file shares +$RECYCLE.BIN/ + +# Mac desktop service store files +.DS_Store + +# SASS Compiler cache +.sass-cache + +# Visual Studio 2014 CTP +**/*.sln.ide + +# Visual Studio temp something +.vs/ + +# VS 2015+ +*.vc.vc.opendb +*.vc.db + +# Rider +.idea/ + +**/node_modules/* + +# Added by Jskonst +.vscode/ +Properties/ + +##### +# End of core ignore list, below put you custom 'per project' settings (patterns or path) +##### \ No newline at end of file diff --git a/Anagrams.Tests/Anagrams.Tests.csproj b/Anagrams.Tests/Anagrams.Tests.csproj new file mode 100644 index 0000000..48ad5db --- /dev/null +++ b/Anagrams.Tests/Anagrams.Tests.csproj @@ -0,0 +1,20 @@ + + + + netcoreapp3.1 + + false + + + + + + + + + + + + + + diff --git a/Anagrams.Tests/Anagrams.Tests.sln b/Anagrams.Tests/Anagrams.Tests.sln new file mode 100644 index 0000000..8d8b39b --- /dev/null +++ b/Anagrams.Tests/Anagrams.Tests.sln @@ -0,0 +1,25 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 16 +VisualStudioVersion = 16.0.29806.167 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Anagrams.Tests", "Anagrams.Tests.csproj", "{9A87C9FA-6174-408A-8EB0-22C581E01879}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {9A87C9FA-6174-408A-8EB0-22C581E01879}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {9A87C9FA-6174-408A-8EB0-22C581E01879}.Debug|Any CPU.Build.0 = Debug|Any CPU + {9A87C9FA-6174-408A-8EB0-22C581E01879}.Release|Any CPU.ActiveCfg = Release|Any CPU + {9A87C9FA-6174-408A-8EB0-22C581E01879}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {0D43EC57-6ED8-42CC-87DE-F9A7F0AA827B} + EndGlobalSection +EndGlobal diff --git a/Anagrams.Tests/AnagramsTests.cs b/Anagrams.Tests/AnagramsTests.cs new file mode 100644 index 0000000..1bb4ea2 --- /dev/null +++ b/Anagrams.Tests/AnagramsTests.cs @@ -0,0 +1,51 @@ +using System; +using Xunit; +using Anagrams; + +namespace Anagrams.Tests +{ + public class AnagramsTests + { + [Fact] + public void WordsCarAndCot() + { + Assert.Equal(" 1 (-)", Program.Anagrams("cat", "cot")); + } + + [Fact] + public void WordsCarAndCoz() + { + Assert.Equal(" 2 (-)", Program.Anagrams("cat", "coz")); + } + + [Fact] + public void WordsCarsAndCat() + { + Assert.Equal(" ", Program.Anagrams("cars", "cat")); + } + + [Fact] + public void WordsDeerAndDeep() + { + Assert.Equal(" 1 (-)", Program.Anagrams("deer", "deep")); + } + + [Fact] + public void WordsMrahAndHarm() + { + Assert.Equal(" ", Program.Anagrams("mrah", "harm")); + } + + [Fact] + public void WordsDarkAndYyyy() + { + Assert.Equal(" 4 (-)", Program.Anagrams("dark", "yyyy")); + } + + [Fact] + public void WordsAgarAndGras() + { + Assert.Equal(" 1 (-)", Program.Anagrams("agar", "gras")); + } + } +} diff --git a/Anagrams.sln b/Anagrams.sln new file mode 100644 index 0000000..6b422e2 --- /dev/null +++ b/Anagrams.sln @@ -0,0 +1,25 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 16 +VisualStudioVersion = 16.0.29806.167 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Anagrams", "Anagrams\Anagrams.csproj", "{CD48E038-A8B8-471C-822C-FDC0D53FD77F}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {CD48E038-A8B8-471C-822C-FDC0D53FD77F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {CD48E038-A8B8-471C-822C-FDC0D53FD77F}.Debug|Any CPU.Build.0 = Debug|Any CPU + {CD48E038-A8B8-471C-822C-FDC0D53FD77F}.Release|Any CPU.ActiveCfg = Release|Any CPU + {CD48E038-A8B8-471C-822C-FDC0D53FD77F}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {9BDFA447-1C1F-4F40-AD35-227E20641E60} + EndGlobalSection +EndGlobal diff --git a/Anagrams/Anagrams.csproj b/Anagrams/Anagrams.csproj new file mode 100644 index 0000000..c73e0d1 --- /dev/null +++ b/Anagrams/Anagrams.csproj @@ -0,0 +1,8 @@ + + + + Exe + netcoreapp3.1 + + + diff --git a/Anagrams/Program.cs b/Anagrams/Program.cs new file mode 100644 index 0000000..a1bbac0 --- /dev/null +++ b/Anagrams/Program.cs @@ -0,0 +1,72 @@ +using System; +using System.Collections.Generic; + +namespace Anagrams +{ + public class Program + { + public static Dictionary ConvertStringToLettersDictionary(string str) + { + Dictionary letters = new Dictionary(); + + foreach (char chr in str) + { + if (letters.ContainsKey(chr)) + { + letters[chr]++; + } + else + { + letters.Add(chr, 1); + } + } + + return letters; + } + + public static string Anagrams(string firstWord, string secondWord) + { + if(firstWord.Length != secondWord.Length) + { + return "Слова не равной длинны"; + } + + int result = 0; + Dictionary letters1 = ConvertStringToLettersDictionary(firstWord.ToLower()); + Dictionary letters2 = ConvertStringToLettersDictionary(secondWord.ToLower()); + + int stringLength = firstWord.Length; + + foreach (char chr in letters2.Keys) + { + if(letters1.ContainsKey(chr)) + { + if(letters1[chr] != letters2[chr]) + { + stringLength += letters2[chr] - letters1[chr]; + if(stringLength == firstWord.Length) + { + result += Math.Abs(letters2[chr] - letters1[chr]); + } + } + } + else + { + result += letters2[chr]; + } + } + + if(result == 0) + { + return "Данные слова уже являются анаграммами"; + } + + return $"Следует заменить {result} букв(-ы)"; + } + + static void Main(string[] args) + { + Console.WriteLine(Anagrams("насос", "сосна")); + } + } +} diff --git a/README.md b/README.md index f61d7f1..a64f9c0 100644 --- a/README.md +++ b/README.md @@ -1 +1,9 @@ -# exam_42_2020 \ No newline at end of file +# exam_42_2020 + + +: + + , , +: +cat, cot 1 +cat coz 2 2 . \ No newline at end of file