'SRM'에 해당되는 글 14건

  1. 2009.05.26 SRM 200 DIV 2 (250)
  2. 2009.05.26 SRM 197 DIV 2 (250)
  3. 2009.05.26 SRM 145 DIV 2 (250)
  4. 2009.05.26 SRM 144 DIV 2 (200)

SRM 200 DIV 2 (250)

Programming/SRM Practice 2009. 5. 26. 17:05
SRM 200 DIV 2 (250)
문제 요약 : 연산자 우선순위에 구애받지 말고
0~9까지의 숫자와 +,-,* 연산자를 String형으로 입력받아 계산하여라.

#include <iostream>

#include <string>

using namespace std;

 

class NoOrderOfOperations

{

public:

 int evaluate(string expr);

};

 

int NoOrderOfOperations::evaluate(string expr)

{

 int n = 0, res = 0;

 int flag = 0;

 char op;

 int i = 0;


 
while(expr[i])

 {

  if( '0' <= expr[i] && expr[i] <= '9' )

  {

   if(i == 0) res = atoi(&expr[i]);

   if(flag == 1)

   {

     n = atoi(&expr[i]);

     switch(op)

     {

     case '+':

      res += n;

      break;

     case '-':

      res -= n;

      break;

     case '*':

      res *= n;

      break;

     default:

      break;

     }

     flag = 0;

   }

  }

  else if(flag == 0)

  {

   op = expr[i];

   flag = 1;

  }

  i++;

 }


   return
res;
}

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

SRM 370 DIV 2 (250)  (0) 2009.05.26
SRM 205 DIV 2 (250)  (0) 2009.05.26
SRM 197 DIV 2 (250)  (0) 2009.05.26
SRM 145 DIV 2 (250)  (0) 2009.05.26
SRM 144 DIV 2 (200)  (0) 2009.05.26
:

SRM 197 DIV 2 (250)

Programming/SRM Practice 2009. 5. 26. 16:56
SRM 197 DIV 2 (250)
문제 요약 : 정원에서 일정 수의 식물에 물을 줘야한다.
가로 길과 세로 길의 수가 주어지고, 호스의 길이도 주어진다.
단, 신발이 젖지 말아야 한다는 조건 때문에 길을 따라 돌아다녀야 한다.
몇 번 물을 줘야 하는지 최소한의 수를 구하라. 

#include<iostream>

using namespace std;


class
GardenHose

{

public:

     int countDead(int n,int rowDist, int colDist, int hoseDist);

};


int
GardenHose::countDead(int n, int rowDist, int colDist, int hoseDist)

{

     int cnt = 0;

 

     for(int i = 1 ; i <= n ; i++)

        for(int j = 1 ; j <= n ; j++)

                     if( (rowDist*j) > hoseDist

                   && (rowDist*(n+1-j)) > hoseDist

                   && (colDist*i) > hoseDist

                   && (colDist*(n+1-i)) > hoseDist) cnt++;

 

     return cnt;
}

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

SRM 370 DIV 2 (250)  (0) 2009.05.26
SRM 205 DIV 2 (250)  (0) 2009.05.26
SRM 200 DIV 2 (250)  (0) 2009.05.26
SRM 145 DIV 2 (250)  (0) 2009.05.26
SRM 144 DIV 2 (200)  (0) 2009.05.26
:

SRM 145 DIV 2 (250)

Programming/SRM Practice 2009. 5. 26. 16:30
SRM 145 DIV 2 (250)
문제 요약 : 입력된 문자열에 포함된 문자가
문자열들의 집합에서 몇 번 사용되었는지 세어서 반환하라.

#include <iostream>

#include <vector>

using namespace std;

 

class ImageDithering

{

public:

      int count(string dithered, vector <string> screen);

};

 

int ImageDithering::count(string dithered, vector <string> screen)

{

      int cnt = 0;

 
      
for(int i = 0 ; dithered[i] ; i++)

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

                      for(int k = 0 ; screen[j][k] ; k++)

                              if(dithered[i] == screen[j][k]) cnt++;

      return cnt;
}

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

SRM 370 DIV 2 (250)  (0) 2009.05.26
SRM 205 DIV 2 (250)  (0) 2009.05.26
SRM 200 DIV 2 (250)  (0) 2009.05.26
SRM 197 DIV 2 (250)  (0) 2009.05.26
SRM 144 DIV 2 (200)  (0) 2009.05.26
:

SRM 144 DIV 2 (200)

Programming/SRM Practice 2009. 5. 26. 16:29
SRM 144 DIV 2 (200)
문제 요약 : 입력된 초를 시간:분:초로 바꿔서 반환하라.

#include <iostream>

using namespace std;

 

class Time

{

public:

  string whatTime(int seconds);

};

 

string Time::whatTime(int seconds)

{

  char temp[10];

 

  sprintf(temp, "%d:%d:%d",
          (seconds / 60) / 60, (seconds / 60) % 60, seconds % 60);

  string time = temp;

 

  return time;

}

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

SRM 370 DIV 2 (250)  (0) 2009.05.26
SRM 205 DIV 2 (250)  (0) 2009.05.26
SRM 200 DIV 2 (250)  (0) 2009.05.26
SRM 197 DIV 2 (250)  (0) 2009.05.26
SRM 145 DIV 2 (250)  (0) 2009.05.26
: