結果

問題 No.1475 時計の歯車Easy
ユーザー Minami53Minami53
提出日時 2022-05-12 00:53:09
言語 C#
(.NET 8.0.203)
結果
AC  
実行時間 55 ms / 2,000 ms
コード長 3,014 bytes
コンパイル時間 9,783 ms
コンパイル使用メモリ 144,152 KB
実行使用メモリ 162,964 KB
最終ジャッジ日時 2023-09-26 17:02:45
合計ジャッジ時間 13,194 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 53 ms
29,048 KB
testcase_01 AC 54 ms
29,140 KB
testcase_02 AC 53 ms
31,112 KB
testcase_03 AC 53 ms
28,836 KB
testcase_04 AC 52 ms
28,960 KB
testcase_05 AC 54 ms
29,092 KB
testcase_06 AC 53 ms
28,956 KB
testcase_07 AC 54 ms
29,040 KB
testcase_08 AC 54 ms
30,828 KB
testcase_09 AC 53 ms
30,900 KB
testcase_10 AC 53 ms
28,904 KB
testcase_11 AC 53 ms
29,156 KB
testcase_12 AC 53 ms
28,860 KB
testcase_13 AC 53 ms
30,956 KB
testcase_14 AC 54 ms
28,784 KB
testcase_15 AC 54 ms
31,024 KB
testcase_16 AC 53 ms
28,780 KB
testcase_17 AC 53 ms
28,744 KB
testcase_18 AC 54 ms
28,844 KB
testcase_19 AC 53 ms
28,864 KB
testcase_20 AC 52 ms
28,764 KB
testcase_21 AC 53 ms
28,812 KB
testcase_22 AC 52 ms
28,960 KB
testcase_23 AC 52 ms
28,812 KB
testcase_24 AC 53 ms
29,088 KB
testcase_25 AC 53 ms
28,816 KB
testcase_26 AC 54 ms
29,092 KB
testcase_27 AC 53 ms
28,736 KB
testcase_28 AC 53 ms
28,852 KB
testcase_29 AC 53 ms
29,040 KB
testcase_30 AC 53 ms
29,024 KB
testcase_31 AC 54 ms
28,936 KB
testcase_32 AC 55 ms
28,740 KB
testcase_33 AC 54 ms
31,100 KB
testcase_34 AC 53 ms
28,896 KB
testcase_35 AC 53 ms
31,140 KB
testcase_36 AC 52 ms
28,832 KB
testcase_37 AC 52 ms
28,904 KB
testcase_38 AC 53 ms
31,184 KB
testcase_39 AC 53 ms
28,916 KB
testcase_40 AC 53 ms
28,904 KB
testcase_41 AC 54 ms
28,848 KB
testcase_42 AC 53 ms
29,044 KB
testcase_43 AC 54 ms
31,008 KB
testcase_44 AC 53 ms
29,068 KB
testcase_45 AC 53 ms
162,964 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
  Determining projects to restore...
  Restored /home/judge/data/code/main.csproj (in 136 ms).
.NET 向け Microsoft (R) Build Engine バージョン 17.0.0-preview-21470-01+cb055d28f
Copyright (C) Microsoft Corporation.All rights reserved.

  プレビュー版の .NET を使用しています。https://aka.ms/dotnet-core-preview をご覧ください
  main -> /home/judge/data/code/bin/Release/net6.0/main.dll
  main -> /home/judge/data/code/bin/Release/net6.0/publish/

ソースコード

diff #

using System;
using System.Collections.Generic;

namespace No1475_gomi
{
    class Program
    {
        static void Main(string[] args)
        {
            // 時計の数を読み込む
            // コンソールから1行読み込んでintに変換
            int num = Convert.ToInt32(Console.ReadLine());

            // 最終的な結果を格納するリスト
            List<List<int>> result = new List<List<int>>();

            // 部品を読み込む
            // 時計(行)の数だけ繰り返し
            for (int i=0; i < num; i++)
            {
                // 1行読み込む
                string tmpLine = Console.ReadLine();
                // 半角スペースで行を分割
                string[] LineSplit = tmpLine.Split(" ");

                // 1行をint型リストに置き換え
                // stringのままでは扱いにくいため.下準備のようなものであり本問の本質的部分ではないです.
                List<int> LineList = new List<int>(); // 1行をint型に置き換えるリスト
                for (int j =0; j < Convert.ToInt32(LineSplit[0]) + 1; j++)
                {
                    if(j != 0) // 先頭要素は部品数ではないため無視する
                    {
                        LineList.Add(Convert.ToInt32(LineSplit[j]));
                    }                    
                }

                // 読み込んだ行から部品のリストを作成する
                // ソートアルゴリズムを利用・ここではバブルソート
                for (int j = 0; j < LineList.Count; j++)
                {
                    for (int k = 0; k < LineList.Count - 1 - j; k++)
                    {
                        if(LineList[k] < LineList[k + 1]) // k番目の要素がk+1番目の要素より小さい
                        {
                            // 入れ替えを行う
                            int tmpNum = LineList[k];
                            LineList[k] = LineList[k + 1];
                            LineList[k+1] = tmpNum;
                        }
                    }                    
                }

                result.Add(LineList); // 最終的な結果のリストに格納

            } // 時計(行)の数だけ繰り返し 終了

            // 結果の出力
            foreach (var row in result)
            {
                // 1行出力用の変数
                string outputLine = "";

                foreach (var cell in row)
                {
                    // 1要素追加
                    outputLine += cell;
                    // 最終要素でないなら半角スペースも追加
                    if(row.IndexOf(cell) != row.Count - 1)
                    {
                        outputLine += " ";
                    }
                }
                // コンソールに書き出す
                Console.WriteLine(outputLine);
            }
        }
    }
}
0