2015年3月12日 星期四

[2015][Quiz][Week03] Quiz02 - 60373020H

Quiz02-1

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Quiz2_1
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("從1000到9999:ABCD=(AB)^2+(cd)^2");
            Console.WriteLine("================");
            for (int i = 1000; i <= 9999; i++)
            {
                int a = i % 100;
                int b = i / 100;
                if (i == a * a + b * b)
                {
                    Console.WriteLine("{0}", i);
                }
            }
            Console.ReadKey();
        }
    }
}


Quiz02-2

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Quiz2_2
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("請輸入一個數");
            Console.WriteLine("================");
            int x = int.Parse(Console.ReadLine());
            if (x / 100 == 0)
            {
                Console.WriteLine("輸入錯誤");
            }
            if (x / 100 < 100)
            {
                for (int i = 1000; i <= x; i++)
                {
                    int a = i % 100;
                    int b = i / 100;
                    if (i == a * a + b * b)
                    {
                        Console.WriteLine("{0}", i);
                    }
                }          
            }
            Console.WriteLine("================");

            if (x / 10000 < 100)
            {
                for (int i = 1000; i <= 9999; i++)
                {
                    int a = i % 100;
                    int b = i / 100;
                    if (i == a * a + b * b)
                    {
                        Console.WriteLine("{0}", i);
                    }
                }
                for (int i = 10000; i <= x; i++)
                {
                    int a = i % 100;
                    int b = i / 100;
                    int b2 = b % 100;
                    int c = b /100;

                    if (i==a*a*a+b2*b2*b2+c*c*c)
                    {
                        Console.WriteLine("{0}", i);
                    }
                }              
            }


          
            Console.ReadKey();
        }
    }
}



沒有留言:

張貼留言