본문 바로가기

프로그래밍

[주인장] 2010년 5월 20일 C# 실습~

//호텔 문 열고 닫고하고.. 최종 열려있는 문 찾기 실습예제
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Hotel
{
    class Program
    {
        static void Main(string[] args)
        {
            /*
            int[] door = new int[100];
            int i,human = 1;
            int count = 0;
            while (human < 101)
            {
                for (i = human; i < 101; i=i+human)
                {
                    door[i-1] = (door[i-1]==1? 0 : 1);
                }
                human++;
            }
            for (i = 0; i < 100; i++)
            {
                if (door[i] == 1)
                {
                    Console.WriteLine("{0}는 열려있다.", i + 1);
                    count++;
                }
            }
            Console.WriteLine("열려있는 방의 갯수는 {0}개이다.", count);
            */

            int count = 0;
            for (int i = 1; i < 101; i++)
            {
                for (int j = 1; j <= i; j++)
                {
                    if (i % j == 0)
                        count++;
                }
                if (count % 2 == 1)
                {
                    Console.WriteLine("{0}번 방문이 열려있습니다", i);
                }
                count = 0;
            }
           
               
        }
    }
}


약수의 갯수가 홀수면 열려있고, 짝수면 닫혀있는.. 예제임을 늦게 알아버린...-ㅅ-;;