Coding Test Study : 2022 Summer - 06/28

Checking·2022년 6월 28일
0

Coding Test Study

목록 보기
19/22

1주차 (06/28) - Class 2

1085 - 직사각형에서 탈출

#include <iostream>

using namespace std;

int main() {
	int x, y, w, h, result = 1000;
    cin >> x >> y >> w >> h;
    
  	if (result > x) result = x;
    if (result > y) result = y;
    if (result > w-x) result = w-x;
    if (result > h-y) result = h-y;
    
    cout << result;
    
    return 0;
}

4153 - 직각삼각형

#include <iostream>

using namespace std;

int main() {
	while (true) {
    	int side1, side2, hypotenuse;
        cin >> side1 >> side2 >> hypotenuse;

        if (side1 + side2 + hypotenuse == 0)
            break;
        
        if (hypotenuse < side1) {
        	int num = side1;
            side1 = hypotenuse;
            hypotenuse = num;
        }
        
        if (hypotenuse < side2) {
        	int num = side2;
            side2 = hypotenuse;
            hypotenuse = num;
        }
        
        cout << ((side1 * side1 + side2 * side2 == hypotenuse * hypotenuse) ? "right\n" : "wrong\n");
    }
    
    return 0;
}

10250 - ACM 호텔

#include <iostream>
#include <string>

using namespace std;

int main() {
	int times;
    cin >> times;
    
    for (int i=0; i<times; i++) {
    	int h, w, n;
        cin >> h >> w >> n;

        string floor, room;

        room = to_string((n - 1) / h + 1);
        floor = to_string((n % h == 0) ? h : n % h) + ((room.length() != 2) ? "0" : "");

        cout << floor << room << "\n";
    }
	
	return 0;
}

2231 - 분해합

#include <iostream>

using namespace std;

int main() {
	int num, result = 0;
    cin >> num;
    
    for (int i=0; i<num; i++) {
    	int nowValue = i;
        
        for (int j=i; j>0; j/=10) 
        	nowValue += j % 10;
           
		if (nowValue == num) {
        	result = i;
            break;
        }
    }

	cout << result;

	return 0;
}

2292 - 벌집

#include <iostream>

using namespace std;

int main() {
	int num;
    cin >> num;
    
    for (int i=1, maxRoom=1; maxRoom <= num; i++) 
    	maxRoom += 6 * i;

	return 0;
}
profile
(ง ᐖ)ว

0개의 댓글