Coding Test Study : 2022 Summer - 07/04

Checking·2022년 7월 4일
0

Coding Test Study

목록 보기
22/22

1주차 (07/04) - Class 2

2751 - 수 정렬하기 2

#include <iostream>
#include <list>

using namespace std;

int main() {
    int times;
    list <int> numList;
    cin >> times;

    for (int i=0; i<times; i++) {
        int num;
        cin >> num;
        
        numList.push_back(num);
    }

    numList.sort();

    for (int n:numList)
        cout << n << "\n";
    
    return 0;
}

2869 - 달팽이는 올라가고 싶다

#include <iostream>

using namespace std;

int main() {
    int up, down, height;
    double days;
    cin >> up >> down >> height;

    days = double (height - down) / (up - down);

    cout << int(days) + ((int(days) != days) ? 1 : 0);
    
    return 0;
}

7568 - 덩치

#include <iostream>
#include <vector>

using namespace std;

int main() {
    int times;
    cin >> times;
    
    vector <pair<int, int>> infoList;
    vector <int> rank(times, 1);

    for (int i=0; i<times; i++) {
        int weight, height;
        cin >> weight >> height;

        infoList.push_back({weight, height});
    }

    for (int i=0; i<times; i++) 
        for (int j=0; j<times; j++) 
            if (infoList[i].first < infoList[j].first && infoList[i].second < infoList[j].second)
                rank[i]++;

    for (int r:rank)
        cout << r << " ";
    
    
    return 0;
}

10814 - 나이순 정렬

#include <iostream>
#include <string>
#include <list>

using namespace std;

bool cmp(pair<pair<int, string>, int> user1, pair<pair<int, string>, int> user2) {
    if (user1.first.first != user2.first.first)
        return user1.first.first < user2.first.first;

    return user1.second < user2.second;
}

int main() {
    list <pair<pair<int, string>, int>> userList;
    int times;
    cin >> times;

    for (int i=0; i<times; i++) {
        int age;
        string name;
        cin >> age >> name;

        userList.push_back({{age, name}, i});
    }

    userList.sort(cmp);

    for (pair<pair<int, string>, int> u:userList)
        cout << u.first.first << " " << u.first.second << "\n";
    
    return 0;
}

11650 - 좌표 정렬하기

#include <iostream>
#include <list>

using namespace std;

bool cmp(pair<int, int> pos1, pair<int, int> pos2) {
    if (pos1.first != pos2.first)
        return pos1.first < pos2.first;

    return pos1.second < pos2.second;
}

int main() {
    list <pair<int, int>> posList;
    int times;
    cin >> times;

    for (int i=0; i<times; i++) {
        int x, y;
        cin >> x >> y;

        posList.push_back({x, y});
    }

    posList.sort(cmp);

    for (pair<int, int> p:posList)
        cout << p.first << " " << p.second << "\n";
    
    return 0;
}
profile
(ง ᐖ)ว

1개의 댓글

comment-user-thumbnail
2023년 9월 6일

Your dedication to presenting a balanced perspective geometry dash on this theme, addressing both its positive and challenging aspects, is both commendable and enriching for readers seeking a well-rounded understanding.

답글 달기