갓비니

2020/04/05 코딩 문제 연습(5단계 / 백준 10817,2523,2446) C++ 본문

Programming/코딩 문제 풀이

2020/04/05 코딩 문제 연습(5단계 / 백준 10817,2523,2446) C++

갓비니 2020. 4. 5. 03:29

오늘 푼문제. 5단계 3,4,5번

5단계 3번 세 수<10871번>

너무 오래 걸렸다...

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
#include<iostream>
using namespace std;
 
int main() {
    
    int arr[3];
    
    cin >> arr[0>> arr[1>> arr[2];
 
 
    int max_num=0, min_num=0;
 
 
    for (int i = 0; i < 3; i++) {
        if (arr[i] > arr[max_num])max_num = i;
        if (arr[i] < arr[min_num])min_num = i;
        
    }
    if ((arr[0== arr[1])&& (arr[1== arr[2])) {
        max_num = 0;
        min_num = 1;
    }
    
    for (int i = 0; i < 3; i++) {
        if (!((i == max_num) || (i == min_num)))
            cout << arr[i];
    }
    
 
}
http://colorscripter.com/info#e" target="_blank" style="color:#4f4f4ftext-decoration:none">Colored by Color Scripter
 

내가 한건 너무 .. 편법 코딩같다 ㅠㅠ

 

다른사람들이 한 것을 찾아보니 그냥 if문 안에 if, else if를 넣고 하였다...

하지만 간단하고 좋은 것 같다,,,ㅠㅠ

 

 

5단계 4번째 별찍기-13<2523번>

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#include<iostream>
using namespace std;
 
int main() {
    int a;
    cin >> a;
 
    for (int i = 1; i <= a; i++) {
        for (int j = 0; j < i; j++) {
            cout << "*";
        }
        cout << "\n";
    }
    for (int i = a; i > 1; i--) {
        for (int j = i; j > 1;j-- ) {
            cout << "*";
        }
        cout << "\n";
    }
}
 

 

 

5단계 5번째 문제 별찍기-9 <2446번 문제>

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
31
32
33
34
35
36
37
#include<iostream>
using namespace std;
 
int main() {
    int a;
    cin >> a;
    
    for (int i = a; i > 1;i--) {
        if (i < a) {
            for (int k = 0; k < a - i;k++) {
                cout << " ";
            }
        }
        for (int j = (i*2)-1; j > 0 ; j--) {
            cout << "*";
        }
        cout << "\n";
 
    }
    
 
    for (int i = 1; i <= a; i++) {
        if (i < a) {
            for (int k = i; k < a;k++) {
                cout << " ";
            }
        }
        
        for (int j = 0; j < ((i*2)-1); j++) {
            cout << "*";
        }
        cout << "\n";
    }
 
}
 
 
http://colorscripter.com/info#e" target="_blank" style="color:#4f4f4ftext-decoration:none">Colored by Color Scripter
 

 

한문제 푸는데 왜케 오래걸리는건지... ㅠㅠㅠ;;;