기본 콘텐츠로 건너뛰기

9375 : 패션왕 신해빈 [C++]

이항계수 문제들을 풀다 보니 nCk에 익숙해져서 이 문제도 그렇게 풀려고 했다.

5C2 + 3C1 + 2C1 + ... 요런식으로 하다보니까 빠르게 틀리고 나서 다시 생각해봤는데

생각보다 이지했다.

clothes 3종류, pants 2종류, headgear 3종류라고 하면 

구하는 공식은 

 = {clothes(3) + 안입음(1)} * {pants(2) + 안입음(1)} * {headgear(3) + 안입음(1)}
 - 아무것도 안입음(1)

이렇게 되겠다. 채점중 50%에서 계속 틀렸다고 나와서 20분동안 헤매다가

cout << F.GetAnswer() <<endl 줄바꿈을 안해줬었다.

당연히 테스트케이스 문제에서는 써줬어야 하는데 실수다

다음부턴 헤매지 말자!

FashionKing::FashionKing(int n)
{
 this->Fashion.push_back("null");
 this->NumberofSort.push_back(0);

 for (int i = 0; i < n; i++)
 {
  string Name;
  string Wear;
  cin >> Name >> Wear;
  for (int j = 0; j < this->Fashion.size(); j++)
  {
   if (this->Fashion[j] == Wear)
   {
    this->NumberofSort[j]++;
    break;
   }
   if (j == this->Fashion.size() - 1)
   {
    this->Fashion.push_back(Wear);
    this->NumberofSort.push_back(1);
    break;
   }
  }
 }
}

long long FashionKing::GetAnswer()
{
 long long Sum = 1;

 for (int i = 1; i < this->NumberofSort.size(); i++)
  Sum *= (long long)(this->NumberofSort[i] + 1);

 return (Sum - 1);
}
<소스 코드>

*Source of the problem = https://www.acmicpc.net/problem/9375
*문제 출처 : BAEKJOON ONLINE JUDGE

댓글

이 블로그의 인기 게시물

1978 : 소수 찾기 [C++]

# include < iostream > # include < vector > using namespace std ; int main ( ) { cin . tie ( NULL ) ; vector < int > Primes ; Primes . push_back ( 2 ) ; Primes . push_back ( 3 ) ; for ( int i = 4 ; i < 1000 ; i + + ) { bool IsPrime = true ; if ( i % 2 = = 0 | | i % 3 = = 0 ) continue ; for ( int j = 4 ; j < i ; j + + ) { if ( i % j = = 0 ) { IsPrime = false ; break ; } } if ( IsPrime ) Primes . push_back ( i ) ; } int N , Count = 0 ; cin > > N ; for ( int i = 0 ; i < N ; i + + ) { int Input ; cin > > Input ; for ( int j = 0 ; j < Primes . size ( ) ; j + + ) if ( Input = = Primes [ j ] ) Count + + ; } cout < < Count < < " \n " ; return 0 ; }

10828 : 스택 [Python]

Stack = [ ] def push ( num ) : Stack . append ( int ( num ) ) def pop ( ) : if len ( Stack ) > 0 : print ( Stack . pop ( ) ) else : print ( - 1 ) def size ( ) : print ( len ( Stack ) ) def empty ( ) : if len ( Stack ) == 0 : print ( 1 ) else : print ( 0 ) def top ( ) : if len ( Stack ) > 0 : print ( Stack [ len ( Stack ) - 1 ] ) else : print ( - 1 ) TestCase = int ( input ( ) ) while TestCase > 0 : Command = input ( ) if Command == 'top' : top ( ) elif Command == 'pop' : pop ( ) elif Command == 'empty' : empty ( ) elif Command == 'size' : size ( ) else : push ( Command [ 5 : ] ) TestCase - = 1