Advertisement
Schnuk

809

Jan 17th, 2021
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.13 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4.  
  5. namespace ExamTasks
  6. {
  7.     class Program
  8.     {
  9.         static void Main(string[] args)
  10.         {
  11.             int n = int.Parse(Console.ReadLine());
  12.             string stringN = n.ToString();
  13.             int multiplicity = 0;
  14.             StringBuilder str = new StringBuilder();
  15.             if (stringN.Length % 3 == 0)
  16.                 multiplicity = 0;
  17.             if (stringN.Length % 3 == 1)
  18.             {
  19.                 str.Append(stringN[0].ToString() + " ");
  20.                 multiplicity = 1;
  21.             }
  22.             if (stringN.Length % 3 == 2)
  23.             {
  24.                 str.Append(stringN[0].ToString() + stringN[1].ToString() + " ");
  25.                 multiplicity = 2;
  26.             }
  27.             for (int i = multiplicity; i + 2 < n.ToString().Length; i += 3)
  28.             {
  29.                 str.Append(stringN[i].ToString() + stringN[i + 1].ToString() + stringN[i + 2].ToString());
  30.                 if (i + 3 < n.ToString().Length - 1)
  31.                     str.Append(" ");
  32.             }
  33.             Console.WriteLine(str);
  34.         }
  35.     }
  36. }
  37.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement