본문 바로가기

전체 글332

프린터 *프린터(스택/큐) 중요도 대기목록, location 위치의 문서가 몇번째로 인쇄되는지. 인쇄 대기목록의 젤 처음을 꺼냄. 대기목록에서 중요도가 가장 높으면 인쇄. 아니면 젤뒤로 넣음. #include #include #include using namespace std; int solution(vector priorities, int location) { int answer = 0; deque que; for(int i = 0; i 2019. 9. 5.
이상한 문자 만들기 *이상한 문자 만들기 공백을 기준으로 짝수는 대문자 홀수는 소문자 변환하기. 0번째 인덱스는 짝수로 처리. #include #include using namespace std; string solution(string s) { string answer = ""; int count = 0; for(int i = 0; i 2019. 9. 5.
예산 *예산(정렬) 신청한 금액 배열, 예산이 있음. 예산으로 물품 구매 가능한 부서 최대값. #include #include #include using namespace std; int solution(vector d, int budget) { int answer = 0; sort(d.begin(), d.end()); for(int i : d) { budget -= i; if(budget 2019. 9. 5.
시저암호 * 시저암호(string) 각 알파벳을 일정한 거리만큼 밀어서 다른 알파벳으로 바꿈. Z - A, z - a 로 바뀜. 공백은 공백. #include #include using namespace std; string solution(string s, int n) { string answer = ""; int pos; for(int i = 0; i = 'a') ? 'a' : 'A'; answer += pos + (s[i] - pos + n) % 26; } } return answer; } Colored by Color Scriptercs 2019. 9. 5.
약수의 합 *약수의 합 #include using namespace std; int solution(int n) { int answer = 0; /**case1*/ O(n) for(int i = 1; i 2019. 9. 5.
문자열을 정수로 바꾸기 *문자열을 정수로 바꾸기(음수도 stoi 됨;) #include #include using namespace std; int solution(string s) { int answer = 0; answer = stoi(s); return answer; } cs 2019. 9. 5.