-
1966. 숫자를 정렬하자코딩 테스트/SW Expert Academy 2021. 6. 30. 23:43
SW Expert Academy
SW 프로그래밍 역량 강화에 도움이 되는 다양한 학습 컨텐츠를 확인하세요!
swexpertacademy.com
문제 이해
-> 주어진 N 길이의 숫자열을 오름차순으로 정렬하여 출력하는 프로그램
문제 주의
-> N은 5이상 50 이하의 수
// https://blockdmask.tistory.com/76 list STL 참고
문제 풀이
-> list STL을 사용하여 문제 풀이
-> 테스트 케이스를 list의 끝에 삽입하는 것을 반복문을 통해 수행
-> list STL 내부의 sort() 함수를 통해 정렬
-> iterator 을 활용하여 list를 순서대로 출력
#include <list> #include<iostream> using namespace std; int main() { int testCaseCount, testMax, testCase; cin >> testCaseCount; list<int> tempList; list<int>::iterator tempPopNum; for (int i = 0; i < testCaseCount; i++) { cin >> testMax; tempList.clear(); for (int j = 0; j < testMax; j++) { cin >> testCase; tempList.push_back(testCase); } tempList.sort(); cout << "#" << i + 1 << " "; for (tempPopNum = tempList.begin(); tempPopNum != tempList.end(); tempPopNum++) cout << *tempPopNum << " "; cout << endl; } return 0; }
'코딩 테스트 > SW Expert Academy' 카테고리의 다른 글
1976. 시각 덧셈 (0) 2021.07.26 1204. 최빈수 구하기 (0) 2021.07.03 1926. 간단한 369게임 (0) 2021.06.29 1928. Base64 Decoder (0) 2021.06.28 1954. 달팽이 숫자 (0) 2021.06.24