티스토리 뷰

[2063] : 중간 값 찾기

#include <iostream>
using namespace std;
 
int main(void){
    int N, mid;
    cin >> N;
    mid = N / 2;
    int arr[N];
    for(int i = 0; i < N; i++)
        cin >> arr[i];
    for (int i = 0; i < N - 1; i++){
        int min = i;
        for(int j = i + 1; j < N; j++)
            if(arr[j] < arr[min])
                min = j;
        int tmp = arr[min];
        arr[min] = arr[i];
        arr[i] = tmp;
    }
    cout << arr[mid] << endl;
    return 0;
}

[2068] : 최대 수 구하기

#include <iostream>

using namespace std;

int main(void) {
	int testCase, input[10];
	int large[100];
	cin >> testCase;
	for (int i = 0; i < testCase; i++) {
		int big = -1;
		for (int j = 0; j < 10; j++) {
			cin >> input[j];
			if (input[j] > big) big = input[j];
		}
		large[i] = big;
	}
	for (int i = 0; i < testCase; i++)
		cout << "#" << i + 1 << " " << large[i] << endl;
	return 0;
}

[2070] 큰 놈, 작은 놈, 같은 놈

#include <iostream>

using namespace std;

int main(void) {
	int testCase, input[2];
	char sym[100];
	cin >> testCase;
	for (int i = 0; i < testCase; i++) {
		for (int j = 0; j < 2; j++)
			cin >> input[j];
		if (input[0] == input[1]) sym[i] = '=';
		else if (input[0] < input[1]) sym[i] = '<';
		else sym[i] = '>';
	}
	for (int i = 0; i < testCase; i++)
		cout << "#" << i + 1 << " " << sym[i] << endl;
	return 0;
}

[2071] : 평균 값 구하기

#include <iostream>
#include <math.h>
using namespace std;

int main(void) {

	int testCase, input[10];
	int oddAve[10000];

	cin >> testCase;
	for (int i = 0; i < testCase; i++) {
		int sum = 0;
		for (int j = 0; j < 10; j++) {
			cin >> input[j];
			sum += input[j];
		}
		oddAve[i] = round(sum / 10.0);
	}
	for (int i = 0; i < testCase; i++)
		cout << "#" << i + 1 << " " << oddAve[i] << endl;
	return 0;
}

[2072] : 홀수만 더하기

#include <iostream>
using namespace std;

int main(void) {

	int testCase, input[10];
	int oddSum[10000];

	cin >> testCase;
	for (int i = 0; i < testCase; i++) {
		int sum = 0;
		for (int j = 0; j < 10; j++) {
			cin >> input[j];
			if (input[j] % 2 != 0) sum += input[j];
		}
		oddSum[i] = sum;
	}
	for (int i = 0; i < testCase; i++)
		cout << "#" << i + 1 << " " << oddSum[i] << endl;
	return 0;
}

 

'CS > 알고리즘' 카테고리의 다른 글

[SWEA] D2 : 1285, 1288, 1976, 1945  (0) 2019.06.15
[SWEA] D2 : 1986, 1984, 1204, 1284  (0) 2019.06.15
[SWEA] D2 : 1926, 1989, 2005, 2007  (0) 2019.06.15
[SWEA] D1 : 1545, 1933, 1936, 2019  (0) 2019.06.15
[SWEA] D1 : 2046, 2047, 2050, 2056, 2058  (0) 2019.06.15
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2024/04   »
1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30
글 보관함