結果
| 問題 | No.39 桁の数字を入れ替え | 
| コンテスト | |
| ユーザー |  suzu | 
| 提出日時 | 2023-05-16 13:05:57 | 
| 言語 | C#(csc) (csc 3.9.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 27 ms / 5,000 ms | 
| コード長 | 908 bytes | 
| コンパイル時間 | 2,279 ms | 
| コンパイル使用メモリ | 111,620 KB | 
| 実行使用メモリ | 25,984 KB | 
| 最終ジャッジ日時 | 2024-12-14 13:56:44 | 
| 合計ジャッジ時間 | 3,596 ms | 
| ジャッジサーバーID (参考情報) | judge5 / judge2 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 19 | 
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc) Copyright (C) Microsoft Corporation. All rights reserved.
ソースコード
using System;
using System.Linq;
using System.Collections.Generic;
namespace yukicoder
{
	class Programs
	{
		static void Main(string[] args)
		{
			int N = int.Parse(Console.ReadLine());
			var list = new List<int>();
			
			
			int tn = N;
			while(tn > 0)
			{
				list.Add(tn % 10);
				
				tn /= 10;
			}
			
			list.Reverse();
			
			for(int p = 0;p < list.Count - 1;p++)
			{
				int head = list[p];
				int max = -1;
				int maxIndex = -1;
				for(int q = p + 1;q < list.Count;q++)
				{
					int ch = list[q];
					if(max <= ch)
					{
						max = ch;
						maxIndex = q;
					}
					
				}
				
				if(max == -1 || max <= head)
				{
					continue;
				}else
				{
					list[p] = max;
					list[maxIndex] = head;
					break;
				}
			}
			list.Reverse();
			int sum = 0;
			int a = 1;
			foreach(int i in list)
			{
				sum += a * i;
				a *= 10;
			}
			Console.WriteLine(sum);
			
		}
		
	}
	
}
            
            
            
        