문제

https://school.programmers.co.kr/learn/courses/30/lessons/64065

 

프로그래머스

코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.

programmers.co.kr

 

내가 짠 코드

급하게 만들다보니 개판..

#include <string>
#include <vector>

using namespace std;

vector<int> solution(string s) {
    vector<int> answer;

    vector <vector<int>> con;
    vector<int> ss;
    int temp = 0;
    for (int i = 1; i < s.size() -1; i++)
    {
        if (s[i] >= '0' && s[i] <= '9')
        {
            temp *= 10;
            temp += s[i] - '0';
            continue;
        }
        if (s[i] == ',' && s[i-1]!='}')
        {
            ss.push_back(temp);
            temp = 0;
            continue;
        }
        if (s[i] == '}')
        {
            ss.push_back(temp);
            temp = 0;
            con.push_back(ss);
            ss.clear();
            continue;
        }
    }
    //answer.resize(con.size());
    for (int i = 1; i <= con.size(); i++)
    {
        for (int j = 0; j < con.size(); j++)
        {
            if (i == con[j].size())
            {
                for (int l = 0; l < i; l++)
                {
                    bool check = true;
                    for (int k = 0; k < answer.size(); k++)
                    {
                        if (answer[k] == con[j][l]) check = false;
                    }
                    if (check)
                    {
                        answer.push_back(con[j][l]);
                        break;
                    }
                }
            }
        }
    }

    return answer;
}
Posted by pi92

블로그 이미지
pi92

공지사항

Yesterday
Today
Total

달력

 « |  » 2025.5
1 2 3
4 5 6 7 8 9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28 29 30 31

최근에 올라온 글

최근에 달린 댓글

글 보관함