728x90

This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <bits/stdc++.h> | |
using namespace std; | |
int input, sumOdd, minValue = 100; | |
int main(void) { | |
ios::sync_with_stdio(false), cin.tie(nullptr); | |
for (int i = 0; i < 7; i++) { | |
cin >> input; | |
if (input % 2 != 0) { | |
sumOdd += input; | |
if (minValue > input) minValue = input; | |
} | |
} | |
if (minValue == 100) | |
cout << -1; | |
else | |
cout << sumOdd << '\n' << minValue; | |
} | |
// #include <bits/stdc++.h> | |
// #define N 7 | |
// using namespace std; | |
// int main() { | |
// ios::sync_with_stdio(false), cin.tie(nullptr); | |
// int a, min = 101, sum = 0; | |
// for (int i = 0; i < N; i++) { | |
// cin >> a; | |
// if (a % 2 != 0) { | |
// sum += a; | |
// if (a < min) min = a; | |
// } | |
// } | |
// if (sum != 0) { | |
// cout << sum << "\n"; | |
// cout << min; | |
// } else | |
// cout << -1; | |
// } | |
/* | |
홀수(2576) | |
O(N) | |
홀수일 경우 sum에 더하고, 최소값인지 확인하여 min에 저장 | |
홀수가 없을 경우 sum == 0이므로, 0인지 확인 후 출력 | |
마지막 풀이에서는 배열을 굳이 사용하지 않고, 입력받고 바로 확인하는 로직으로 | |
변경 | |
*/ | |
/* 2. array b를 없애고 int min을 이용한 풀이(속도면에서 더 나은듯 하지만 역시 | |
* 배열을 이용) */ | |
/* | |
#include <bits/stdc++.h> | |
#define N 7 | |
using namespace std; | |
int main() { | |
ios::sync_with_stdio(false), cin.tie(nullptr); | |
int a[N]; | |
int sum = 0, min = 101; | |
for (int i = 0; i < N; i++) cin >> a[i]; | |
for (int i = 0; i < N; i++) { | |
if (a[i] % 2 != 0) { | |
sum += a[i]; | |
if (a[i] < min) min = a[i]; | |
} | |
} | |
if (sum != 0) | |
cout << sum << '\n', cout << min; | |
else | |
cout << -1; | |
} | |
*/ | |
/* 1.배열을 이용한 풀이(공간면에서 굳이 배열을 이용할 필요가 없다) */ | |
/* | |
#include <bits/stdc++.h> | |
#define N 7 | |
using namespace std; | |
int main() { | |
ios::sync_with_stdio(false), cin.tie(nullptr); | |
int a[N], b[N]; | |
int sum = 0; | |
for (int i = 0; i < N; i++) cin >> a[i], b[i] = 101; | |
for (int i = 0; i < N; i++) | |
if (a[i] % 2 != 0) b[i] = a[i], sum += a[i]; | |
sort(b, b + N); | |
if (sum != 0) | |
cout << sum << '\n', cout << b[0]; | |
else | |
cout << -1; | |
} | |
*/ | |
// Authored by : pha-ran (soft18) | |
// Co-authored by : - | |
// http://boj.kr/c2a05cf9d222441dba79bba4e9ac5b6e | |
// #include <bits/stdc++.h> | |
// using namespace std; | |
// int main(void) { | |
// ios::sync_with_stdio(0); | |
// cin.tie(0); | |
// int x, odd = 0, sum = 0, min = 100; | |
// 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"; | |
// } |
'Algorithm > C&C++' 카테고리의 다른 글
백준 2309번: 일곱 난쟁이(c/c++, c/cpp) (0) | 2021.10.06 |
---|---|
백준 2587번: 대표값2(c/c++, c/cpp) (0) | 2021.10.06 |
백준 2562번: 최댓값(c/c++, c/cpp) (0) | 2021.10.05 |
백준 2490번: 윷놀이(c/c++, c/cpp) (0) | 2021.10.05 |
백준 2480번: 주사위 세개(c/c++, c/cpp) (0) | 2021.09.29 |