'250'에 해당되는 글 3건

  1. 2009.09.15 SRM 150 DIV 2 (250)
  2. 2009.09.15 SRM 149 DIV 2 (250)
  3. 2009.07.04 SRM 307 DIV 2 (250)

SRM 150 DIV 2 (250)

Programming/SRM Practice 2009. 9. 15. 23:11
SRM 150 DIV 2 (250)
문제 요약 : 지갑을 고치는 데 몇 일을 소비할까?

using System;

 

public class WidgetRepairs

{

    public int days(int[] arrivals, int numPerDay)

    {

        int days = 0;

        int remains = 0;

 

        for (int i = 0; i < arrivals.Length - 1; i++)

        {

            arrivals[i] += remains;

            remains = 0;

 

            if (arrivals[i] == 0) continue;

 

            if (arrivals[i] - numPerDay > 0)

            {

                int temp = arrivals[i] - numPerDay;

 

                if (temp > numPerDay)  remains = temp;

                else arrivals[i + 1] += temp;

            }

            days++;

        }

        days += (arrivals[arrivals.Length - 1] + remains) / numPerDay;

        if ((arrivals[arrivals.Length - 1] + remains) % numPerDay != 0) days++;

        return days;

    }

}


'Programming > SRM Practice' 카테고리의 다른 글

SRM 149 DIV 2 (250)  (0) 2009.09.15
SRM 307 DIV 2 (250)  (0) 2009.07.04
SRM 191 DIV 2 (250)  (0) 2009.05.30
SRM 148 DIV 2 (250)  (0) 2009.05.27
SRM 146 DIV 2 (250)  (0) 2009.05.27
:

SRM 149 DIV 2 (250)

Programming/SRM Practice 2009. 9. 15. 23:04
SRM 149 DIV 2 (250)
문제 요약 : dollars, cents 표기법에 맞게 출력하기

using System;

 

public class FormatAmt

{

    public string amount(int dollars, int cents)

    {

        string res = "", temp = dollars.ToString();

        for (int i = temp.Length - 1; i >= 0; i--)

        {

            res = temp[i] + res;

            if ((temp.Length - i) % 3 == 0 && i != 0) res = "," + res;

        }

        if (cents.ToString().Length > 1) res += "." + cents.ToString();

        else res += ".0" + cents.ToString();

        return "$" + res;

    }

}


'Programming > SRM Practice' 카테고리의 다른 글

SRM 150 DIV 2 (250)  (0) 2009.09.15
SRM 307 DIV 2 (250)  (0) 2009.07.04
SRM 191 DIV 2 (250)  (0) 2009.05.30
SRM 148 DIV 2 (250)  (0) 2009.05.27
SRM 146 DIV 2 (250)  (0) 2009.05.27
:

SRM 307 DIV 2 (250)

Programming/SRM Practice 2009. 7. 4. 06:53
SRM 307 DIV 2 (250)
문제 요약 : 짝이 맞지 않아서 교환해야하는 신발은 총 몇 켤레인가? 

#include <iostream>

#include <vector>

using namespace std;

 

class BootsExchange

{

public:

        int leastAmount(vector <int> left, vector <int> right);

};

 

int BootsExchange::leastAmount(vector <int> left, vector <int> right)

{

        int cnt = 0;

       

        for(int i = 0; i < left.size() ; i++)

        {

               for(int j = 0; j < right.size() ; j++)

               {

                       if(left[i] == right[j])

                       {

                              right[j] = 0;

                              break;

                       }

                       else

                       {

                              if(j == right.size() - 1) cnt++;

                       }

               }

        }

        return cnt;

}

 

'Programming > SRM Practice' 카테고리의 다른 글

SRM 150 DIV 2 (250)  (0) 2009.09.15
SRM 149 DIV 2 (250)  (0) 2009.09.15
SRM 191 DIV 2 (250)  (0) 2009.05.30
SRM 148 DIV 2 (250)  (0) 2009.05.27
SRM 146 DIV 2 (250)  (0) 2009.05.27
: