Advertisement
Siropo

Triple Rotation Of Digits

Dec 29th, 2012
199
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.63 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace triple_rotation
  8. {
  9.     class TripleRotation
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             string getInput = Console.ReadLine();
  14.  
  15.             int K = int.Parse(getInput);
  16.             int getInputLen = getInput.Length;
  17.  
  18.             if (getInputLen > 2)
  19.             {
  20.  
  21.                 string[] getLastChars = new string[3];
  22.                 string finalString = "";
  23.  
  24.                 for (int i = getInput.Length - 1, j = 0; i >= getInput.Length - 3; i--, j++)
  25.                 {
  26.                     getLastChars[j] = getInput[i].ToString();
  27.                 }
  28.  
  29.                 for (int i = 2; i >= 0; i--)
  30.                 {
  31.                     if (getLastChars[i] == "0")
  32.                     {
  33.                         finalString += "";
  34.                     }
  35.                     else
  36.                     {
  37.                         finalString += getLastChars[i];
  38.                     }
  39.                 }
  40.  
  41.                 string removeLast = getInput.Remove(getInput.Length - 3);
  42.                 finalString = finalString + removeLast;
  43.                 Console.WriteLine(finalString);
  44.             }
  45.             else if (getInputLen == 2)
  46.             {
  47.                 string removeLast = getInput.Remove(getInput.Length - 1);
  48.                 char last = getInput[getInput.Length - 1];
  49.  
  50.                 Console.WriteLine(last + removeLast);
  51.             }
  52.             else
  53.             {
  54.                 Console.WriteLine(getInput);
  55.             }
  56.  
  57.         }
  58.     }
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement