출처 : https://www.acmicpc.net/problem/11721

 

11721번: 열 개씩 끊어 출력하기

첫째 줄에 단어가 주어진다. 단어는 알파벳 소문자와 대문자로만 이루어져 있으며, 길이는 100을 넘지 않는다. 길이가 0인 단어는 주어지지 않는다.

www.acmicpc.net

 

쉬운거 어려운거 가리지 않고 열심히 코딩

#include <iostream>
#include <string>
using namespace std;

int main(void) {
	string sString;
	cin >> sString;
	for (int i = 0; i < sString.size(); i++) {
		if (i % 10 == 0 && i != 0) {
			cout << endl;
		}
		cout << sString[i];
    }
    return 0;
}

 

 

https://programmers.co.kr/learn/courses/30/lessons/42583

 

코딩테스트 연습 - 다리를 지나는 트럭

트럭 여러 대가 강을 가로지르는 일차선 다리를 정해진 순으로 건너려 합니다. 모든 트럭이 다리를 건너려면 최소 몇 초가 걸리는지 알아내야 합니다. 다리에는 트럭이 최대 bridge_length대 올라갈

programmers.co.kr

 

스택/큐 문제이다.

큐 자료구조를 사용하여 선입선출(FIFO) 방식으로 풀어보았다.

class Solution {
    public int solution(int bridge_length, int weight, int[] truck_weights) {
        int answer = 0;
		int end = 0;
		int sum = 0;
		int wait = 0;
		int[] start = new int[truck_weights.length];
		boolean p = true;
		while (p) {
			if(answer - start[end] == bridge_length) {
				sum -= truck_weights[end];
				end++;
			}
			
			if(wait<truck_weights.length && sum + truck_weights[wait] <= weight) {
				start[wait] = answer;
				sum += truck_weights[wait];
				wait++;
			}
			answer++;
			if(end == truck_weights.length)
				p = false;
			
		}
		return answer;
    }
}

 

'Coding Test/Programmers' 카테고리의 글 목록 :: 개발공부 (tistory.com)

 

'Coding Test/Programmers' 카테고리의 글 목록

 

hntown43.tistory.com

 

스택/큐 문제이다.

 

import java.util.*;
class Solution {
    public int solution(int[] priorities, int location) {
        int answer = 0;
		ArrayList<Integer> list = new ArrayList<Integer>();
		for (int i : priorities) {
			list.add(i);
		}
		int start = 0;
		while (start < priorities.length) {
			boolean chk = true;
			if (location >= start) {
				for (int i = start + 1; i < priorities.length; i++) {
					if (list.get(start) < list.get(i)) {
						list.add(list.get(start));
						list.remove(start);

						if (location == start)
							location += priorities.length - start - 1;
						else
							location--;

						chk = false;
						break;
					}
				}
			}
			if (chk)
				start++;
		}
		answer = location + 1;
		return answer;
    }
}

출처 : https://www.acmicpc.net/problem/10809

 

10809번: 알파벳 찾기

각각의 알파벳에 대해서, a가 처음 등장하는 위치, b가 처음 등장하는 위치, ... z가 처음 등장하는 위치를 공백으로 구분해서 출력한다. 만약, 어떤 알파벳이 단어에 포함되어 있지 않다면 -1을 출

www.acmicpc.net

 

 

 

#include <iostream>
#include <string>
using namespace std;

int main(void) {
    string sInput;
    int nT;
    cin >> sInput;
    
    for(int i = 97; i < 123; i++) {
        nT = sInput.find(i);
        if (nT > sInput.length()){
            cout << -1 << " ";
            continue;
        }
        cout << sInput.find(i) << " ";
    }
    return 0;
}

출처 : https://www.acmicpc.net/problem/11720

 

11720번: 숫자의 합

첫째 줄에 숫자의 개수 N (1 ≤ N ≤ 100)이 주어진다. 둘째 줄에 숫자 N개가 공백없이 주어진다.

www.acmicpc.net

 

최대 정수의 범위를 넘어가는 예제 3 때문에 문자열로 받아야 하는것이 포인트 

string이나 char*을 쓰면 가능하다.

#include <iostream>
#include <string>
using namespace std;

int main(void) {
    int nLen;
    string nNum;
    int nResult = 0;
    cin >> nLen >> nNum;
    
    for(auto it : nNum) {
        nResult += it - '0';
    }
    
    cout << nResult;
    return 0;
}

+ Recent posts