Notice
Recent Posts
Recent Comments
Link
«   2024/12   »
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
Tags
more
Archives
Today
Total
관리 메뉴

Be Coder

튜플 본문

알고리즘

튜플

ForzaCoding 2020. 4. 30. 14:55

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

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

#include <string>

#include <vector>

#include <algorithm>

#include <set>

using namespace std;

 

vector<int> solution(string s) {

    vector<int> answer;

    vector<int> n;

    vector<pair<intvector<int>>> v;

    set<int> pick;

    string num ="";

    

    for(int i = 1; i < s.size()-1; i++){

        if(s[i] == '{'continue;

        

        if(s[i] == ','){

            if(num.size() == 0){}

            else if(num.size() == 1) n.push_back(atoi(num.c_str()));

            else n.push_back(atoi(num.c_str()));

            num = "";

        }

        else if(s[i] == '}'){

            if(num.size() == 0){}

            else if(num.size() == 1) n.push_back(atoi(num.c_str()));

            else n.push_back(atoi(num.c_str()));

            num = "";

            v.push_back({n.size(), n});

            n.clear();

        }

        else num += s[i];   

    }

    

    sort(v.begin(), v.end());

   

    for(pair<intvector<int>> p : v){

        for(int val : p.second){

            if(pick.count(val) == 0){

                pick.insert(val);

                answer.push_back(val);

            }

        }

    }

    

    return answer;

}

Colored by Color Scripter

cs