11
10

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

C#でAtCoderデビューのための準備

Last updated at Posted at 2021-01-06

AtCoder Beginners Selection から始めてみようとしています。
https://atcoder.jp/contests/abs

####標準入力

// 文字列の入力
string s = Console.ReadLine();

// 整数の入力
long n = long.Parse(Console.ReadLine());

// 文字列配列の入力
string[] inputStrArray = Console.ReadLine().Split(' ');

// 整数配列の入力
long[] inputLongArray = Console.ReadLine().Split(' ').Select(i => long.Parse(i)).ToArray();
int[] array = Console.ReadLine().Split().Select(int.Parse).ToArray();

####配列の初期化

// 配列を生成する
var array = new int[] {0, 2, 4, 6};

// [0,1...] の配列を生成する
var array = Enumerable.Range(0, 5).ToArray(); // {0, 1, 2, 3, 4}

// 初期値が全て同じ配列を生成する
var array = Enumerable.Repeat(-1, 5).ToArray(); // { -1, -1, -1, -1, -1}

####繰り返し for

using System;

namespace Challenge
{
    class ChallengeCsFor
    {
        public static void Main()
        {
            int n = int.Parse(Console.ReadLine());
            int sum = 0;
            for (int i = 0; i < n - 1; i++)
            {
                int value = int.Parse(Console.ReadLine());
                sum = sum + value;
                Console.WriteLine($"sum={sum}");
            }
        }
    }
}

実行結果
image.png

####条件分岐 if else

using System;

namespace Challenge
{
    class ChallengeCsIf
    {
        static void Main(string[] args)
        {
            var s = Console.ReadLine();

            if (int.TryParse(s, out var result))
            {
                Console.WriteLine(result);
            }
            else
            {
                Console.WriteLine("整数に変換できません");
            }
        }
    }
}

実行結果
image.png
image.png
image.png
####例外処理

using System;

namespace Challenge
{
    class ChallengeCsError
    {
        static void Main(string[] args)
        {
            var s = Console.ReadLine();
            try
            {
                Console.WriteLine(int.Parse(s));
            }
            catch
            {
                Console.WriteLine("整数に変換できません");
            }
        }
    }
}

実行結果
image.png
image.png

####ソート

using System;
using System.Linq;
 
namespace Challenge
{
    class ChallengeCsSort
    {
        public static void Main(string[] args)
        {
            int[] array = Console.ReadLine().Split().Select(int.Parse).ToArray();
            Array.Sort(array);
            foreach (int element in array) 
            {
                Console.WriteLine(element);
            }
        }
    }
}

実行結果
image.png

####では始めてみます
[C#でAtCoder Beginners Selection(ABC086A - Product)]
(https://qiita.com/azumabashi/items/33efd2162d69eeede6d8)
[C#でAtCoder Beginners Selection(ABC081A - Placing Marbles)]
(https://qiita.com/azumabashi/items/4eb8ba05cad1c9348538)
[C#でAtCoder Beginners Selection(ABC081B - Shift only)]
(https://qiita.com/azumabashi/items/f943be9e4e5e24f58f79)
[C#でAtCoder Beginners Selection(ABC087B - Coins)]
(https://qiita.com/azumabashi/items/410cdb2536968e587cee)
[C#でAtCoder Beginners Selection(ABC083B - Some Sums)]
(https://qiita.com/azumabashi/items/70abad1412f8e0e0a69e)
[C#でAtCoder Beginners Selection(ABC088B - Card Game for Two)]
(https://qiita.com/azumabashi/items/9445e4cf41f91d9fba27)
[C#でAtCoder Beginners Selection(ABC085B - Kagami Mochi)]
(https://qiita.com/azumabashi/items/6263a59b010e5eda68c5)
[C#でAtCoder Beginners Selection(ABC085C - Otoshidama)]
(https://qiita.com/azumabashi/items/e4d6f7320c4dbc1da2b3)
[C#でAtCoder Beginners Selection(ABC049C - 白昼夢)]
(https://qiita.com/azumabashi/items/ba8d64f991a13ebc5a96)
[C#でAtCoder Beginners Selection(ABC086C - Traveling)]
(https://qiita.com/azumabashi/items/d5f01c270c7690d0d2d6)

####参考

[天才プログラマー2人が語る、高度IT人材の採用のポイントとは?]
(https://dentsu-ho.com/articles/7074)

AtCoder Beginner Contest 042
[https://atcoder.jp/contests/abc042]
(https://atcoder.jp/contests/abc042)

AtCoder Beginner Contest 043
[https://atcoder.jp/contests/abc043]
(https://atcoder.jp/contests/abc043)

[第一回 アルゴリズム実技検定 過去問]
(https://atcoder.jp/contests/past201912-open)

[第二回 アルゴリズム実技検定 過去問]
(https://atcoder.jp/contests/past202004-open)

[第三回 アルゴリズム実技検定 過去問]
(https://atcoder.jp/contests/past202005-open)

[第四回 アルゴリズム実技検定 過去問]
(https://atcoder.jp/contests/past202010-open)

[第五回 アルゴリズム実技検定 過去問]
(https://atcoder.jp/contests/past202012-open)

ピューマ本
[最強最速アルゴリズマー養成講座 プログラミングコンテストTopCoder攻略ガイド]
(https://www.sbcr.jp/product/4797367171/)

螺旋本
[プログラミングコンテスト攻略のためのアルゴリズムとデータ構造]
(https://book.mynavi.jp/ec/products/detail/id=35408)

蟻本
[プログラミングコンテストチャレンジブック [第2版]]
(https://book.mynavi.jp/ec/products/detail/id=22672)

競技プログラミングのための C# (4.0 以降) の Tips 詰め合わせ
[https://emkcsharp.hatenablog.com/entry/2013/Advent]
(https://emkcsharp.hatenablog.com/entry/2013/Advent)

初心者がC#でAtCoderデビューするためのVSProjectテンプレート
[https://qiita.com/sekikatsu/items/93c41c6c937ed1dfcf23]
(https://qiita.com/sekikatsu/items/93c41c6c937ed1dfcf23)

AtCoderで使えそうなC# 7.0~8.0の新機能
[https://www.terry-u16.net/entry/csharp-7-8-new-features-for-atcoder]
(https://www.terry-u16.net/entry/csharp-7-8-new-features-for-atcoder)

11
10
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
11
10

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?