4
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

解いた問題

作成したコード

注意
Contains()メソッドでは、クエリの文字列が市場の文字列の先頭以外含まれる場合も検出されてしまうので、今回の用途では使用しません。

using System;
using System.Collections.Generic;

class Program
{
    static void Main()
    {
        string[] p  = Console.ReadLine().Split(' ');
        int soldStrNum = int.Parse(p[0]);
        int queryNum = int.Parse(p[1]);
        
        string[] soldStr = new string[soldStrNum];
        int[] soldCost = new int[soldStrNum];
        string[] queries = new string[queryNum];
        int[] score = new int[queryNum];
        for(int i=0; i<queryNum; i++)
        {
            score[i] = 0;
        }
        
        for(int i=0; i<soldStrNum; i++)
        {
            string[] input = Console.ReadLine().Split(' ');
            soldStr[i] = input[0];
            soldCost[i] = int.Parse(input[1]);
        }
        
        for(int i=0; i<queryNum; i++)
        {
            queries[i] = Console.ReadLine();
        }
        
        int i_sc = 0;
        foreach(var q in queries)
        {
            for(int i=0; i<soldStrNum; i++)
            {
                if(soldStr[i].StartsWith(q))
                {
                    score[i_sc] += soldCost[i];
                }
            }
            i_sc++;
        }
        
        foreach(var sc in score)
        {
            Console.WriteLine(sc);
        }
    }
}
4
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?