using System; using System.Collections.Generic; using System.Linq; class Program { static string InputPattern = "Input5"; static List GetInputList() { var WillReturn = new List(); if (InputPattern == "Input1") { WillReturn.Add("12"); } else if (InputPattern == "Input2") { WillReturn.Add("21"); } else if (InputPattern == "Input3") { WillReturn.Add("1122"); } else if (InputPattern == "Input4") { WillReturn.Add("999999999"); } else { string wkStr; while ((wkStr = Console.ReadLine()) != null) WillReturn.Add(wkStr); } return WillReturn; } static void Main() { List InputList = GetInputList(); char[] StrArr = InputList[0].ToCharArray(); char[] DescStr = StrArr.OrderByDescending(X => X).ToArray(); ; int DiffFromFirst = -1; int DiffFromLast = -1; for (int I = 0; I <= StrArr.Length - 1; I++) { if (StrArr[I] != DescStr[I]) { DiffFromFirst = I; break; } } for (int I = StrArr.Length - 1; 0 <= I; I--) { if (StrArr[I] != DescStr[I]) { DiffFromLast = I; break; } } if (DiffFromFirst == -1 && DiffFromLast == -1) { Console.WriteLine(StrArr); return; } char SankakuWK = StrArr[DiffFromFirst]; StrArr[DiffFromFirst] = StrArr[DiffFromLast]; StrArr[DiffFromLast] = SankakuWK; Console.WriteLine(new string(StrArr)); } }