結果

問題 No.628 Tagの勢い
ユーザー ooh_23ooh_23
提出日時 2018-01-11 13:44:44
言語 C#(csc)
(csc 3.9.0)
結果
WA  
実行時間 -
コード長 2,784 bytes
コンパイル時間 857 ms
コンパイル使用メモリ 104,704 KB
実行使用メモリ 19,584 KB
最終ジャッジ日時 2024-04-16 20:04:37
合計ジャッジ時間 2,163 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 32 ms
18,688 KB
testcase_01 AC 32 ms
18,560 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 AC 26 ms
18,048 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
権限があれば一括ダウンロードができます
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc)
Copyright (C) Microsoft Corporation. All rights reserved.

ソースコード

diff #

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication2
{
    class Program
    {
        static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());
            Dictionary<string, int> tagScores = new Dictionary<string, int>();
            for(int i = 0; i < N; i++)
            {
                // データの読み取り
                Console.ReadLine();     // 入力データの番号が邪魔(使わないデータ)
                string[] ss = Console.ReadLine().Split();
                int M = int.Parse(ss[0]);      // 配列の1番目がタグの数
                int S = int.Parse(ss[1]);       // 配列の2番目がスコア

                string[] Tag = Console.ReadLine().Split();   // タグの読み取り
                // データをまとめる

                for (int tagNum = 0; tagNum < M; tagNum++)
                {
                    if (tagScores.ContainsKey(Tag[tagNum]))
                    {
                        // Dictionaryにtags[m]と同文字列のキーが既に存在する場合
                        tagScores[Tag[tagNum]] += S;
                    }
                    else {
                        // キーが無い場合
                        tagScores[Tag[tagNum]] = S;
                    }
                }
            }
            // タグとスコアのM分配列を用意する
            string[] tags = new string[tagScores.Count];
            int[] score = new int[tagScores.Count];
            // Dictionaryから配列に入れ直す
            int n = 0;
            foreach(string key in tagScores.Keys)
            {
                tags[n] = key;
                score[n] = tagScores[key];
                n++;
            }
            // 並べ替え
            for(int i = 0; i < score.Length; i++)
            {
                for(int k = i; k < score.Length - 2; k++)
                {
                    if (score[k] < score[k + 1] || score[k] == score[k + 1] && tags[k].CompareTo(tags[k + 1]) == 1)
                    {
                        int tmp = score[k];
                        score[k] = score[k + 1];
                        score[k + 1] = tmp;

                        string tmp2 = tags[k];
                        tags[k] = tags[k + 1];
                        tags[k + 1] = tmp2;
                    }
                }
            }
            // 出力処理
            int count = 10;
            if (count > tags.Length)
            {
                count = tags.Length;
            }


            for (int i = 0; i < count; i++)
            {
                Console.WriteLine(tags[i] + " " + score[i]);
            }
        }
    }
}
0