티스토리 뷰

 

#include <stdio.h>
#include <string.h>
#define STDNUM 8
#define STDNUMCNT 4
#define MAXVAL 99999;

int intNum[STDNUMCNT][STDNUM], tempNum[STDNUMCNT][STDNUM], answer[2][100],answer2[2][100];
char chrNum[STDNUMCNT][STDNUM];
void setting();

void main(){

                int i,j,k,temp;
                int cnt[2][4] = {{0,0,0,0},{0,0,0,0}};        //각 줄의 0을 제외한 숫자의 갯수가 됨

        printf("\n학번 %d개를 차례로 임력해주세요.\n",STDNUMCNT);

        for(i=0;i<STDNUMCNT;i++){
                scanf("%s",&chrNum[i][0]);
        }
       
        // 입력받은 문자열을 인트로 바꾸어 저장
        for(i=0;i<STDNUMCNT;i++){
                for(j=0;j<STDNUM;j++){
                                        if(chrNum[i][j]==NULL) break;        //NULL을 만나면 다음줄로 이동
                                        if(chrNum[i][j]!='0'){                        //0이 아닌것만 차례로 저장
                                                intNum[i][cnt[0][i]]=((int)chrNum[i][j])-48;
                                                cnt[0][i]++;
                                        }
                }
        }

                printf("**입력받은수 배열에 입력**\n");
                for(j=0;j<STDNUMCNT;j++){
                        for(i=0;i<STDNUM;i++){
                                printf("[%d]",intNum[j][i]);
                        }
                        printf("\n");
                }

                for(i=0;i<STDNUMCNT;i++){        //각행에 대해서
                        for(j=0;j<cnt[0][i];j++){        //원소의 수만큼 행을 돌아       
                                for(k=j+1;k<cnt[0][i];k++){        //내림차순
                                        if(intNum[i][j]<intNum[i][k]){        //스왑
                                                temp = intNum[i][j];
                                                intNum[i][j] = intNum[i][k];
                                                intNum[i][k] = temp;
                                        }
                                }
                        }
                }
               
                printf("**내림차순**\n");
               
                for(j=0;j<STDNUMCNT;j++){
                        for(i=0;i<STDNUM;i++){
                                printf("[%d]",intNum[j][i]);
                        }
                        printf("\n");
                }
       
                for(i=0;i<STDNUMCNT;i++){        //각행에 대해서
                        temp = MAXVAL;
                        for(j=0;j<cnt[0][i];j++){        //원소의 수만큼 행을 돌아       
                                        if(intNum[i][j]<temp){
                                                temp = tempNum[i][cnt[1][i]++] = intNum[i][j];
                                        }
                        }
                       
                }
       
                printf("**중복된 수 제거**\n");
       
                for(j=0;j<STDNUMCNT;j++){
                        for(i=0;i<STDNUM;i++){
                                printf("[%d]",tempNum[j][i]);
                        }
                        printf("\n");
                }
                printf("\n\n최종답안 출력\n\n");
                int p=0,p2=0,p3=0;
                //현재 수식 출력
                for(i=0;i<STDNUMCNT;i=i+2){        //각행에 대해서
                        for(j=0;j<cnt[1][i];j++){        //원소의 수만큼 행을 돌아       
                               
                                if(NULL==tempNum[i+1][j]) break;        //차수가 부족하면 먼저 종료
                                printf("%dx^%d +",tempNum[i+1][j],tempNum[i][j]);
                       
                                p++;
                        }
                        if(0==i){
                                printf("   X  ");
                                p2=p;
                        }else{
                                p3=p;
                        }
                        p=0;
                }
                printf("\n = ");
               
                int cn=0, cn2=0;
                //차수합
                for(i=0;i<p2;i++){
                        for(j=0;j<p3;j++){
                                answer[0][cn++] = tempNum[0][i] + tempNum[2][j];
                        }
                }

                //계수곱
                for(i=0;i<p2;i++){
                        for(j=0;j<p3;j++){
                                answer[1][cn2++] = tempNum[1][i] * tempNum[3][j];
                        }
                }

                //최종답안 출력
                for(i=0;i<=p2*p3;i++){
                        printf("%dx^%d + ",answer[1][i],answer[0][i]);
                }
                printf("\n");
}

반응형
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2024/12   »
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
글 보관함