LoginSignup
0
0

More than 1 year has passed since last update.

はじめに

競技プログラミングで、頻出する入力値の取得に関するスニペットです。
競技プログラムの楽しいところは、アルゴリズムを使って解くところですので、入力値の処理のところはスニペットで楽してしまいましょう。

1つの入力値(INT型)

サンプル

using System;
using System.Linq;

namespace sample
{
    class Program
    {
        static void Main(string[] args)
        {
            int input = int.Parse(Console.ReadLine());
        }
    }
}

スペース区切りの入力値(INT型)

  • サンプル
using System;
using System.Linq;

namespace sample
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] input = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
            int S = input[0];
            int P = input[1];
        }
    }
}

スペース区切りの入力値(String型)

  • サンプル
using System;
using System.Linq;

namespace sample
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] input = Console.ReadLine().Split(' ');
        }
    }
}

入力値に含まれる特定の文字数を数える

  • サンプル

1の数を数えます。

using System;
using System.Linq;

namespace sample
{
    class Program
    {
        static void Main(string[] args)
        {
            int count = Console.ReadLine().Where(n => n.Equals('1')).Count();
        }
    }
}
0
0
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
0
0