https://dev-repository.tistory.com/66


'C & C++ > Baekjoon' 카테고리의 다른 글

백준 4673 - 셀프 넘버  (0) 2017.12.27
백준 4344 - 평균은 넘겠지  (0) 2017.12.27
백준 2920 - 음계  (0) 2017.12.27
백준 2908 - 상수  (0) 2017.12.27
백준 2839 - 설탕 배달  (0) 2017.12.27



<접근 방법>

1. ascending인지를 체크한다.

1-1. ascending이면 "ascending"을 출력 후 종료

2. descending인지를 체크한다.

2-1. descending이면 "descending"을 출력 후 종료

3. ascending과 descending이 모두 아니면 "mixed"를 출력 후 종료



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
#include <iostream>
 
using namespace std;
int main(int argc, char *argv[]) {
    int input[8];
    bool ascending = true;
    bool descending = true;
    
    for(int i=0; i<8; i++)
        cin >> input[i];
    
    for(int i=0; i<8; i++) {
        if(input[i] != (i+1)) {
            ascending = false;
            break;
        }
    }
    
    if(!ascending) {
        for(int i=7; i>=0; i--) {
            if(input[7-i] != (i+1)) {
                descending = false;
                break;
            }
        }
    }
    
    if(ascending)
        cout << "ascending" << endl;
    else if(descending)
        cout << "descending" << endl;
    else
        cout << "mixed" << endl;
        
    return 0;
}
cs


'C & C++ > Baekjoon' 카테고리의 다른 글

백준 4344 - 평균은 넘겠지  (0) 2017.12.27
백준 2941 - 크로아티아 알파벳  (0) 2017.12.27
백준 2908 - 상수  (0) 2017.12.27
백준 2839 - 설탕 배달  (0) 2017.12.27
백준 2742 - 기찍 N  (0) 2017.12.27


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
#include <iostream>
#include <string>
 
using namespace std;
 
int main(void) {
    int A, B;
    cin >> A;
    cin >> B;
    string sA, sB;
    sA = to_string(A);
    sB = to_string(B);
    string sA2 = "";
    string sB2 = "";
 
    for(int i=sA.length()-1; i>=0; i--) {
        sA2.append(1, sA.at(i));
    }
    for(int i=sB.length()-1; i>=0; i--) {
        sB2.append(1, sB.at(i));
    }
 
    int newA, newB;
    newA = stoi(sA2);
    newB = stoi(sB2);
 
    if(newA > newB)
        cout << newA << endl;
    else
        cout << newB << endl;
 
    return 0;
}
cs


'C & C++ > Baekjoon' 카테고리의 다른 글

백준 2941 - 크로아티아 알파벳  (0) 2017.12.27
백준 2920 - 음계  (0) 2017.12.27
백준 2839 - 설탕 배달  (0) 2017.12.27
백준 2742 - 기찍 N  (0) 2017.12.27
백준 2741 - N 찍기  (0) 2017.12.27


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>
#include <stdio.h>
 
int main(void) {
    int weight;
    int ea3, ea5;
    
    ea3 = 0;
    ea5 = 0;
    
    scanf("%d"&weight);
    
    if(weight % 5 == 0){
        ea5 = weight/5;
        weight = 0;
    } else {
        ea5 = weight/5;
        while(true) {
            if((weight - ea5*5)%3 == 0) {
                ea3 = (weight - ea5*5)/3;
                break;
            } else {
                ea5 -= 1;
            }
            if(ea5 == -1) {
                ea3 = -1;
                break;
            }
        }
    }
    
    if(ea3 == -1)
        std::cout << "-1" << std::endl;
    else {
        std::cout << ea3+ea5 << std::endl;
    }
}
cs


'C & C++ > Baekjoon' 카테고리의 다른 글

백준 2920 - 음계  (0) 2017.12.27
백준 2908 - 상수  (0) 2017.12.27
백준 2742 - 기찍 N  (0) 2017.12.27
백준 2741 - N 찍기  (0) 2017.12.27
백준 2739 - 구구단  (0) 2017.12.27


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#include <iostream>
#include <stdio.h>
 
int main(void) {
    int N;
    
    std::cin >> N;
    
    while(true) {
        printf("%d\n", N);
        if(N--==1)
            break;
    }
        
    return 0;
}
cs


'C & C++ > Baekjoon' 카테고리의 다른 글

백준 2908 - 상수  (0) 2017.12.27
백준 2839 - 설탕 배달  (0) 2017.12.27
백준 2741 - N 찍기  (0) 2017.12.27
백준 2739 - 구구단  (0) 2017.12.27
백준 2675 - 문자열 반복  (0) 2017.12.27

+ Recent posts