見出し画像

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

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

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

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

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

問題:ITP1_8_A

using System;
using System.Collections.Generic;
using System.Linq;

namespace ITP_1_8A
{
   class Program
   {
       static void Main(string[] args)
       {
           var N = Console.ReadLine();
           string n ="";
           foreach (var item in N)
           {
               if (char.IsUpper(item))
               {
                   n += Char.ToLower(item);
               }
               else n += Char.ToUpper(item);
           }
           Console.WriteLine(n);
           return;
       }
   }
}

問題:ITP1_8_B

using System;
using System.Collections.Generic;
using System.Linq;

namespace ITP_1_8B
{
   class Program
   {
       static void Main(string[] args)
       {
           int n = 0;

           while (true)
           {
               var line = Console.ReadLine();

               if (line == "0") break;
               foreach (var item in line)
               {
                   n += Int32.Parse(item.ToString());
               }
               Console.WriteLine("{0}", n);
               n = 0;
           }
           return;
       }

   }
}

問題:ITP1_8_C

using System;
using System.Collections.Generic;
using System.Linq;

namespace ITP_1_8C
{
   class Program
   {
       static void Main(string[] args)
       {
           string str = "";
           while (true)
           {
               var N = Console.ReadLine();
               str += N;
               if (N == null) break;
           }

           int n = 0;
           for (char i = 'a'; i <= 'z'; i++)
           {
               foreach (var item in str)
               {
                   if (i == Char.ToLower(item))
                   {
                       n++;
                   }
               }
               Console.WriteLine("{0} : {1}", i, n);
               n = 0;
           }
           return;
       }
   }
}

問題:ITP1_8_D

解説:円状の文字列を表現するために同じ文字列を連結させています。

using System;
using System.Collections.Generic;
using System.Linq;

namespace ITP_1_8D
{

   class Program
   {
       static void Main(string[] args)
       {
           var N = Console.ReadLine();
           var S = Console.ReadLine();

           N += N;      

           if (N.IndexOf(S)>=0)
           {
               Console.WriteLine("Yes");
           }
           else
           {
               Console.WriteLine("No");
           }
           return;
       }
   }
}

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