반응형
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
// student_table.cpp: 콘솔 응용 프로그램의 진입점을 정의합니다.
//
 
#include "stdafx.h"
 
int score[20][7= { 0 };
int student = 0, i = 0, j = 0;
int student_no = 0;
int rank[20= { 0 };
 
void print_score() {
    int i, j;
    i = j = 0;
    printf("  학번  국어  영어  수학  총점  평균  석차\n");
    for (i = 0; i < student; i++) {
        for (j = 0; j < 7; j++) {
            printf("%6d", score[i][j]);
        }
        printf("\n");
    }
}
int main()
{
    printf("학생 수를 입력 해 주세요 = ");
    scanf_s("%d"&student);
 
    for (int i = 0; i < student; i++) {
        printf("%d번 학생의 학번은 ?", i);
        scanf_s("%d"&(score[i][0]));
            
        printf("%d번 학생의 국어 점수 :", i);
        scanf_s("%d"&(score[i][1]));
 
        printf("%d번 학생의 영어 점수 :", i);
        scanf_s("%d"&(score[i][2]));
 
        printf("%d번 학생의 수학 점수 :", i);
        scanf_s("%d"&(score[i][3]));
    }
    print_score();
    //총점 계산
    for (int i = 0; i < student; i++) {
        for (int j = 1; j <= 3; j++) {
            score[i][4+= score[i][j];
        }
    }
    print_score();
    //평균계산
    for (int i = 0; i < student; i++) {
            score[i][5]=score[i][4/ 3;
    }
    print_score();
    //rank 배열에 입력
    for (int i = 0; i < student; i++) {
        rank[i]=score[i][4];
    }
    //rank 배열 정렬
    for (int i = 0; i < student; i++) {
        for (int j = i + 1; j < student; j++) {
            if (rank[i] < rank[j]) {
                int tmp = rank[i];
                rank[i] = rank[j];
                rank[j] = tmp;
            }
 
        }
    }
    // rank배열 출력
    for (int i = 0; i < student; i++) {
        printf("%d ", rank[i]);
    }
    printf("\n");
    // 석차 배열에 입력
    for (int i = 0; i < student; i++) {
        for (int j = 0; j < student; j++) {
            if (rank[j] == score[i][4])
                score[i][6= j+1;
        }
    }
    print_score();
    return 0;
}
 
 
cs

 

 

 

//석차 구하는 함수

for (int i=0; i<student; i++){

score[i][6] =1; // 초기화

for (int j=0;j<student; j++){

if (score[i][5]<score[j][5]){

score[i][6]++;

}

}

// 이 함수를 쓰는게 좀더 편한 것 같다..

 


 // 학번 순으로 정렬
 for (int i = 0; i < student; i++) {
  for (int j = i + 1; j < student; j++) {
   if (score[i][0] > score[j][0]) {
    for (int k = 0; k < 7; k++) {
     int tmp = score[i][k];
     score[i][k] = score[j][k];
     score[j][k] = tmp;

    }
   }
  }
 }

// 정렬부분 누락 됨 추가 필요.

 

 

반응형

'Study > C' 카테고리의 다른 글

C언어 - 포인터 이해  (0) 2018.09.07
C언어 - EOF  (0) 2018.09.07
C언어 - 탐색, 정렬, 순위  (0) 2018.09.07
C언어 - Stack으로 구현한 자동차 주차장  (0) 2018.09.06
C언어(자료구조) - Stack 구현  (0) 2018.09.06
반응형
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
// Prob_01.cpp: 콘솔 응용 프로그램의 진입점을 정의합니다.
//
 
#include "stdafx.h"
int park[100= { 0 };
int way[100= { 0 };
int park_top = 0;
int way_top = 0;
int num = 0;
int num_out = 0;
int mode = 0;
int out_car = 0;
 
int push(int value) {
    park[park_top] = value;
    park_top++;
    way_top--;
    return park_top;
}
int push_way(int value) {
    way[way_top] = value;
    way_top++;
    return way_top;
}
int pop() {
    park_top--;
    way_top++;
    way[way_top] = park[park_top];
    return park[park_top];
}
 
int main()
{
    while (1) {
        printf("동작을 선택하세요 (1. 입차 2.출차 3.주차장 상태보기 ) : ");
        scanf_s("%d"&mode);
        if (mode == 1) {
            printf("1. 자동차 번호를 입력해 주세요 : ");
            scanf_s("%d"&num);
            push(num);
            printf("자동차가 주차되었습니다. 차량번호 : %d \n", park[park_top - 1]);
            way_top = 0;
        }
        else if (mode == 2) {
            printf("2. 출차 할 자동차 번호를 입력 해 주세요 :");
            scanf_s("%d"&num_out);
            for (int i = 0; i < park_top; i++) {
                if (num_out == park[i]) out_car = 1;
            }
            if (out_car == 1) {
                printf("출차 할 차량이 있습니다. 출차를 위해 다른 차량을 출차합니다.\n");
                while (num_out != park[park_top]) {
                    if (num_out == park[park_top]) { park_top--break; }
                    else if (num_out != park[park_top]) {
                        pop();
                    }
                    printf("출차 : %d\n", park[park_top]);
                    printf("막다른길 : ");
                    for (int i = 1; i < way_top; i++) {
                        printf("%d   ", way[i]);
                    }
                    printf("\n주차장 : ");
                    for (int i = 0; i < park_top; i++) {
                        printf("%d  ", park[i]);
                    }
                    printf("\n");
                }
                printf("%d 차량이 출차 되었습니다.\n", park[park_top]);
                printf("막다른길의 차들을 다시 주차장에 주차합니다.\n");
                
                while (way_top >= 1) {
                    push(way[way_top-1]);
                    printf("입차 : %d\n", way[way_top]);
                    printf("막다른길 : %d ");
                    for(int i = 0; i < way_top-1; i++) {
                        printf("%d   " ,way[i]);
                    }
                    printf("\n주차장 : ");
                    for (int i = 0; i < park_top-1; i++) {
                        printf("%d   ", park[i]);
                    }
                    printf("\n");
                }
            }
            else
                printf("출차 할 차량이 없습니다.\n");
        }
        else if (mode == 3) {
 
            for (int i = 0; i < park_top; i++) {
                printf("%d  \n", park[i]);
            }
        }
    }
    return 0;
}
 
cs

 

 

반응형

'Study > C' 카테고리의 다른 글

C언어 - 학생 Table(총점, 평균, 석차)  (0) 2018.09.07
C언어 - 탐색, 정렬, 순위  (0) 2018.09.07
C언어(자료구조) - Stack 구현  (0) 2018.09.06
C언어 - goto문  (0) 2018.08.29
C언어 - 구조체(학생 성적 구조체 만들기)  (0) 2018.08.29
반응형

 

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
 
#include "stdafx.h"
int stack[100];
int top = 0;
 
int push(int value) {
    stack[top] = value; // 스택에 값을 저장
    top++// top 증가
    return top; // top 반환
}
int pop() {
    top--// top 감소
    return stack[top];  //값 반환
}
int main()
{
    push(100);
    push(200);
    push(300);
    printf("%d\n"pop());
    printf("%d\n"pop());
    printf("%d\n"pop());
 
    return 0;
}
 
cs

 

 

반응형

+ Recent posts