Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Text;
- namespace ExamTasks
- {
- class Program
- {
- static void Main(string[] args)
- {
- int n = int.Parse(Console.ReadLine());
- string stringN = n.ToString();
- int multiplicity = 0;
- StringBuilder str = new StringBuilder();
- if (stringN.Length % 3 == 0)
- multiplicity = 0;
- if (stringN.Length % 3 == 1)
- {
- str.Append(stringN[0].ToString() + " ");
- multiplicity = 1;
- }
- if (stringN.Length % 3 == 2)
- {
- str.Append(stringN[0].ToString() + stringN[1].ToString() + " ");
- multiplicity = 2;
- }
- for (int i = multiplicity; i + 2 < n.ToString().Length; i += 3)
- {
- str.Append(stringN[i].ToString() + stringN[i + 1].ToString() + stringN[i + 2].ToString());
- if (i + 3 < n.ToString().Length - 1)
- str.Append(" ");
- }
- Console.WriteLine(str);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement