백준 문제풀이

백준 2576번 - C++

diligent_gideok 2022. 4. 12. 01:50
#include <bits/stdc++.h>
using namespace std;

// sort 를 사용하지 않는경우
int main(void){
  ios::sync_with_stdio(0);
  cin.tie(0);

  int x, odd = 0, sum = 0, min = 100; // odd :홀수 갯수, sum : 홀수 합, min : 홀수들 중 최솟값

  for (int i = 0; i < 7; i++) {
	cin >> x;

	if (x & 1) {
	  odd += 1;
	  sum += x;

	  if (x < min) {
		min = x;
	  }
	}
  }

  if (odd) cout << sum << "\n" << min;
  else cout << "-1";
}​
#include <bits/stdc++.h>
using namespace std;


int main(void) {
	ios::sync_with_stdio(0);
	cin.tie(0);
	int result=0;
	int arr[7];
	for (int i = 0; i < 7; i++) cin >> arr[i];
	sort(arr, arr + 7);
	for (int i = 0; i < 7; i++) if (arr[i] % 2 == 1) result += arr[i];
	if (result == 0) cout << -1;
	else cout << result << '\n';
	for (int i = 0; i < 7; i++) {
		if (arr[i] % 2 == 1) {
			cout << arr[i];
			break;
		}
	}
}

'백준 문제풀이' 카테고리의 다른 글

백준 2752번 - C++  (0) 2022.04.12
백준 2587번 - C++  (0) 2022.04.12
백준 2562번 - C++  (0) 2022.04.12
백준 2557번 - C++  (0) 2022.04.12
백준 2490번 - C++  (0) 2022.04.12