별의 공부 블로그 🧑🏻‍💻
728x90
728x170
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#include <iostream>
 
#define NUM 10
 
using namespace std;
 
int main()
{
    int tmp, mark = 0, count = 1;
    int ary[NUM];
    int a[NUM], b[NUM];
 
    cout << "Input " << NUM << " Numbers : ";
    for (int i = 0; i < NUM; i++) {
        cin >> ary[i];
    }
 
    /* 1. 배열 정렬 (Sorting Array) */
    for (int i = 0; i < NUM - 1; i++) {
        for (int j = i + 1; j < NUM; j++) {
            if (ary[j] < ary[i]) {     // 오름차순 정렬 (Sorting with Increasing Order)
                tmp = ary[j];
                ary[j] = ary[i];
                ary[i] = tmp;
            }
        }
    }
 
 
    /* 2. 숫자 분류 & 개수 파악 (Classification of the Numbers in Array & Grasping the Number of each Number in Array) */         
    a[0= ary[0];
 
    for (int i = 1; i < NUM; i++) {
        if (ary[i - 1!= ary[i]) {
            a[count] = ary[i];
            b[count - 1= i - mark;
            mark = i;
            count++;
        }
    }   // end of for
 
    b[count - 1= NUM - mark;
 
    /* 결과 출력 (Printing Out the Result) */
    cout << endl << "[RESULTS]" << endl << endl;
    cout << "mark : " << mark << endl;
    cout << "N : ";
    for (int i = 0; i < count; i++) {
        cout << a[i] << " ";
    }
    cout << endl;
 
    cout << "# : ";
    for (int i = 0; i < count; i++) {
        cout << b[i] << " ";
    }
    cout << endl;
 
    return 0;
cs

 

배열 요소 정리 : 배열에 담긴 수를 분류하고, 그 개수를 각각 출력하기

(Arrangement of Elements in Array : Classification of the Numbers which are located in each index & Grasping the Number of each Number in Array)

 

 [TEST1]

 

 Input 10 Numbers : 1 2 3 4 5 6 7 8 9 10

 

 [RESULTS]

 

 mark : 9
 N : 1 2 3 4 5 6 7 8 9 10
 # : 1 1 1 1 1 1 1 1 1 1

 

 [TEST2]

 

 Input 10 Numbers : 1 1 2 2 2 3 3 3 3 4

 

 [RESULTS]

 

 mark : 9
 N : 1 2 3 4
 # : 2 3 4 1

 

728x90
그리드형(광고전용)
⚠️AdBlock이 감지되었습니다. 원할한 페이지 표시를 위해 AdBlock을 꺼주세요.⚠️
starrykss
starrykss
별의 공부 블로그 🧑🏻‍💻


📖 Contents 📖