Coding Test/SW Expert Academy
-
[SWEA] 1970. 쉬운 거스름돈 c++Coding Test/SW Expert Academy 2022. 11. 16. 17:08
문제 S마켓에서 손님에게 거슬러 주어야 할 금액 N이 입력되면 돈의 최소 개수로 거슬러 주기 위하여 각 종류의 돈이 몇 개씩 필요한지 출력하라. N이 32850일 경우, 50,000 원 : 0개 10,000 원 : 3개 5,000 원 : 0개 1,000 원 : 2개 500 원 : 1개 100 원 : 3개 50 원 : 1개 10 원 : 0개 문제 해결 #include #include using namespace std; int main(int argc, char** argv) { int test_case; int T; cin>>T; int cash = 50000; for(test_case = 1; test_case > n; cout
-
[SWEA] 1974. 스도쿠 검증 c++Coding Test/SW Expert Academy 2022. 11. 16. 16:33
문제 9 X 9 크기의 스도쿠 퍼즐의 숫자들이 주어졌을 때, 위와 같이 겹치는 숫자가 없을 경우, 1을 정답으로 출력하고 그렇지 않을 경우 0 을 출력한다. 문제 해결 처음에는 1~9 까지의 합을 이용해서 문제를 풀어나갔지만, 10개 test중 5개만 계속 통과해서 방법을 바꾸었다. 1~9가 나왔는지 검사하는 방법으로 풀었다. #include #include #include using namespace std; int main(int argc, char** argv) { int test_case; int T; cin>>T; for(test_case = 1; test_case > board[i][j]; check[0][i][board[i][j]] = true; //행 검사 check[1][j][board[..
-
[SWEA] 1976. 시각 덧셈 c++Coding Test/SW Expert Academy 2022. 11. 16. 11:56
문제 ※ SW Expert 아카데미의 문제를 무단 복제하는 것을 금지합니다. 시 분으로 이루어진 시각을 2개 입력 받아, 더한 값을 시 분으로 출력하는 프로그램을 작성하라. (시각은 12시간제로 표시한다. 즉, 시가 가질 수 있는 값은 1시부터 12시이다.) input output 3 3 17 1 39 8 22 5 10 6 53 2 12 #1 4 56 #2 1 32 #3 9 5 문제 해결 #include using namespace std; int main(int argc, char** argv) { int test_case; int T; cin>>T; for(test_case = 1; test_case > h1 >> m1 >> h2 >> m2; int h = 0, m = 0; m = (m1 + m2) ..
-
[SWEA] 1979. 어디에 단어가 들어갈 수 있을까 c++Coding Test/SW Expert Academy 2022. 11. 16. 11:26
문제 ※ SW Expert 아카데미의 문제를 무단 복제하는 것을 금지합니다. N X N 크기의 단어 퍼즐을 만들려고 한다. 입력으로 단어 퍼즐의 모양이 주어진다. 주어진 퍼즐 모양에서 특정 길이 K를 갖는 단어가 들어갈 수 있는 자리의 수를 출력하는 프로그램을 작성하라. input output 2 5 3 0 0 1 1 1 1 1 1 1 0 0 0 1 0 0 0 1 1 1 1 1 1 1 0 1 5 3 1 0 0 1 0 1 1 0 1 1 1 0 1 1 1 0 1 1 0 1 0 1 1 1 0 #1 2 #2 6 문제 해결 행우선 2중for문, 열우선 2중for문으로 연속된 1의 개수와 k가 같은지 검사하면 된다. #include #include #include using namespace std; int mai..
-
[SWEA] 1983. 조교의 성적 매기기 c++Coding Test/SW Expert Academy 2022. 11. 15. 17:02
문제 ※ SW Expert 아카데미의 문제를 무단 복제하는 것을 금지합니다. 10 개의 평점을 총점이 높은 순서대로 부여하는데, 각각의 평점은 같은 비율로 부여할 수 있다. 예를 들어, N 명의 학생이 있을 경우 N/10 명의 학생들에게 동일한 평점을 부여할 수 있다. 입력으로 각각의 학생들의 중간, 기말, 과제 점수가 주어지고, 학점을 알고싶은 K 번째 학생의 번호가 주어졌을 때, K 번째 학생의 학점을 출력하는 프로그램을 작성하라. [제약사항] 1. N은 항상 10의 배수이며, 10이상 100이하의 정수이다. (10 ≤ N ≤ 100) 2. K는 1 이상 N 이하의 정수이다. (1 ≤ K ≤ N) 3. K 번째 학생의 총점과 다른 학생의 총점이 동일한 경우는 입력으로 주어지지 않는다. [입력] 입력은..
-
[SWEA] 1984. 중간 평균값 구하기 c++Coding Test/SW Expert Academy 2022. 11. 15. 14:22
문제 10개의 수를 입력 받아, 최대 수와 최소 수를 제외한 나머지의 평균값을 출력하는 프로그램을 작성하라. (소수점 첫째 자리에서 반올림한 정수를 출력한다.) 문제 해결 1. sort함수를 사용하여 오름차순 정렬을 한다. 2. accumulate함수를 사용하여 벡터 원소들의 총 합을 구한다. 최댓값, 최소값을 제외하기 위해 vec.begin() + 1 ~ vec.end() - 1로 범위 지정 한다. 3. 소수점 계산을 위해 double형에 계산한 값을 저장한다. 4. round함수를 사용하여 소수점 첫째 자리에서 반올림한다. (floor 함수를 사용한다면 결과에 0.5를 더하면 된다.) #include #include #include #include #include using namespace std;..
-
[SWEA] 1989. 초심자의 회문 검사 c++Coding Test/SW Expert Academy 2022. 11. 15. 12:33
문제 "level" 과 같이 거꾸로 읽어도 제대로 읽은 것과 같은 문장이나 낱말을 회문(回文, palindrome)이라 한다. 단어를 입력 받아 회문이면 1을 출력하고, 아니라면 0을 출력하는 프로그램을 작성하라. 문제 해결 reverse함수를 사용하여 string의 순서를 반전시키고 비교하는 방법으로 문제를 풀었다. #include #include using namespace std; int main(int argc, char** argv) { int test_case; int T; cin>>T; for(test_case = 1; test_case > str; cout
-
[SWEA] 2001. 파리 퇴치 c++Coding Test/SW Expert Academy 2022. 11. 15. 12:23
문제 N x N 배열 안의 숫자는 해당 영역에 존재하는 파리의 개수를 의미한다. M x M 크기의 파리채를 한 번 내리쳐 최대한 많은 파리를 죽이고자 한다. 파리를 잡을 수 있는 최댓값을 구하는 문제이다. [제약 사항] 1. N 은 5 이상 15 이하이다. 2. M은 2 이상 N 이하이다. 3. 각 영역의 파리 갯수는 30 이하 이다. [입력] 가장 첫 줄에는 테스트 케이스의 개수 T가 주어지고, 그 아래로 각 테스트 케이스가 주어진다. 각 테스트 케이스의 첫 번째 줄에 N 과 M 이 주어지고, 다음 N 줄에 걸쳐 N x N 배열이 주어진다. [출력] 출력의 각 줄은 '#t'로 시작하고, 공백을 한 칸 둔 다음 정답을 출력한다. (t는 테스트 케이스의 번호를 의미하며 1부터 시작한다.) input out..