Day6. Namespace style

This commit is contained in:
Electrominch
2022-10-07 16:36:27 +03:00
parent 62104da8f1
commit 5cae083979
51 changed files with 589 additions and 202 deletions

View File

@@ -0,0 +1,11 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<RootNamespace>_557._Reverse_Words_in_a_String_III</RootNamespace>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
</Project>

View File

@@ -0,0 +1,9 @@
namespace _557._Reverse_Words_in_a_String_III;
internal class Program
{
static void Main(string[] args)
{
Console.WriteLine(new Solution().ReverseWords("God Ding"));
}
}

View File

@@ -0,0 +1,25 @@
using System.Text;
namespace _557._Reverse_Words_in_a_String_III;
public class Solution
{
public string ReverseWords(string s)
{
StringBuilder sb = new StringBuilder();
for (int i = 0; i < s.Length; i++)
{
if (s[i] == ' ')
sb.Append(' ');
else
{
int startIndex = i;
while (i < s.Length - 1 && s[i + 1] != ' ')
i++;
for (int r = i; r >= startIndex; r--)
sb.Append(s[r]);
}
}
return sb.ToString();
}
}