위장(오답1)

고장난·2021년 5월 20일
0

코딩스터디(오답)

목록 보기
1/9
#include <string>
#include <vector>
#include <algorithm>

using namespace std;

bool SortSecCol(const vector<string>& v1, const vector<string>& v2){
    return v1[1]<v2[1];
}

int solution(vector<vector<string>> clothes) {
    int answer = 1;
    int temp=0;
    sort(clothes.begin(),clothes.end(),SortSecCol);
    
    for(int j=0;j<clothes.size();j++){
        if(j==clothes.size()-1){
            if(clothes[1][j]==clothes[1][j-1]){
            answer=answer*(temp+1)-1;}
            else{
                answer=answer*2-1;
            }
        }
        else{
            if(clothes[1][j]==clothes[1][j+1]){
                temp++;
            }
            else{
                temp++;
                answer=answer*(temp+1);
                temp=0;
                
            }
            
        }
            
    }
    
    
    return answer;
}

오답

profile
훈련중

0개의 댓글