アイズオンラインジャッジメント(AOJ)のプログラムコード置き場(C#) [ITP1_5]

こんにちは。シジミです。

この記事はAOJで回答したコードを随時置いていきます。

構成としまして、以下のように三弾構成にしています。

・問題:「問題文リンク」
・「説明や注意書き」
・「コード」

環境はvisual sutadio 2019、言語はC#です。


問題:ITP1_5A

using System;

namespace ITP_1_5A
{
   class Program
   {
       static void Main(string[] args)
       {
           while (true)
           {
               string[] inputs = Console.ReadLine().Split(' ');
               int a = int.Parse(inputs[0]);
               int b = int.Parse(inputs[1]);
               if (a == 0 && b == 0) break;
               for (int i = 0; i < a; i++)
               {
                   string area = new string('#', b);
                   Console.WriteLine(area);
                  
               }
               Console.WriteLine("");
           }
       }
   }
}

問題:ITP1_5B

using System;
using System.Collections.Generic;

namespace ITP_1_5B
{
   class Program
   {
       static void Main(string[] args)
       {
           List<int> A = new List<int>();
           List<int> B = new List<int>();
           int i = 0;

           while (true)
           {

               string[] inputs = Console.ReadLine().Split(' ');
               A.Add(int.Parse(inputs[0]));
               B.Add(int.Parse(inputs[1]));

               if (A[i] == 0 && B[i] == 0) break;
               for (int h = 0; h < A[i]; h++)
               {
                   for (int j = 0; j < B[i]; j++)
                   {
                       if ((0 < j && j < B[i]-1) && (0 < h && h < A[i]-1))
                       {
                           Console.Write(".");
                       }
                       else
                       {
                           Console.Write("#");
                       }
                   }
                   Console.WriteLine("");

               }
               Console.WriteLine("");
               i++;
           }

       }
   }
}

問題:ITP1_5C

using System;
using System.Collections.Generic;

namespace ITP_1_5C
{
   class Program
   {
       static void Main(string[] args)
       {
           List<int> A = new List<int>();
           List<int> B = new List<int>();
           int i = 0;

           while (true)
           {

               string[] inputs = Console.ReadLine().Split(' ');
               A.Add(int.Parse(inputs[0]));
               B.Add(int.Parse(inputs[1]));

               if (A[i] == 0 && B[i] == 0) break;
               for (int h = 0; h < A[i]; h++)
               {
                   for (int j = 0; j < B[i]; j++)
                   {
                       if ((j + h )% 2 == 1)
                       {
                           Console.Write(".");
                       }
                       else
                       {
                           Console.Write("#");
                       }
                   }
                   Console.WriteLine("");

               }
               Console.WriteLine("");
               i++;
           }

       }
   }
}

問題:ITP1_5D

この問題は最後に改行を入れるのを忘れないようにしましょう

using System;
using System.Collections.Generic;

namespace ITP_1_5C
{
   class Program
   {
       //void Call(int n);
       static void Main(string[] args)
       {
           int inputs = int.Parse(Console.ReadLine());
           var call = new Program();

           call.Call(inputs);
           Console.WriteLine("");

           return;
       }
       public void Call(int n)
       {
           int i = 1;
           int l = 0;
           int m = 0;

           while (i <= n)
           {
               l = i;

               if (i % 3 == 0 && i != 0)
               {
                   Console.Write(" ");

                   Console.Write("{0}", i);
               }
               else
               {
                   while (l > 0)
                   {

                       if (l % 10 == 3 && i != m)
                       {
                           Console.Write(" ");

                           Console.Write("{0}", i);
                           m = i;
                       }

                       l /= 10;

                   }

               }
               i++;
           }

       }
   }
}


この記事が気に入ったらサポートをしてみませんか?