MUstar

IoT C언어 0710 - EX14_3A

Jul 15th, 2017
89
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <math.h>
  4.  
  5. int int_com(char *st1, char *st2, int *sc1, int *sc2);
  6. char char_com(char *st1, char *st2, int *sc1, int *sc2);
  7. void output(char (*store)[20], int (*score)[7]);
  8.  
  9. int main(void)
  10. {
  11.     char store[4][20] = {"관악점","강남점","명동점","대림점"};
  12.     int score[4][7] ={
  13.     {70,45,100,92,150,81,0},
  14.     {88,92,77,30,52,55,0},
  15.     {50,90,88,75,77,49,0},
  16.     {120,92,80,150,130,105,0}};
  17.     char sv_store[4][20];
  18.     int sv_score[4][7],i,j;
  19.  
  20.  
  21.     for(i=0;i<4;i++)
  22.     {
  23.         strcpy(sv_store[i],store[i]);
  24.         for(j=0;j<7;j++)
  25.         {
  26.             sv_score[i][j] = score[i][j];
  27.         }
  28.     }
  29.  
  30.  
  31.     for(i=0;i<4;i++)
  32.     {
  33.         int temp=0;
  34.         for(j=0;j<6;j++)
  35.             temp+=score[i][j];
  36.         double temp2 = (double)temp/6;
  37.         //score[i][6] = (int)floor(temp2+0.5); //아...쓰는 편한데...   리눅스에서는 일반적에서는 컴파일에러.
  38.         int temp3 = temp/6;
  39.         if((temp2-(double)temp3)>=0.5) temp3++;
  40.         score[i][6] = temp3;
  41.     }
  42.  
  43.     printf("실적별 출력...\n");
  44.     int_com(store[0],store[1],score[0],score[1]);
  45.     int_com(store[0],store[2],score[0],score[2]);
  46.     int_com(store[0],store[3],score[3],score[3]);
  47.     int_com(store[1],store[2],score[1],score[2]);
  48.     int_com(store[1],store[3],score[1],score[3]);
  49.     int_com(store[2],store[3],score[2],score[3]);
  50.     output(store,score);
  51.     printf("\n\n지점별 출력...\n");
  52.     output(sv_store,sv_score);
  53.    
  54.     return 0;
  55. }
  56. int int_com(char *st1, char *st2, int *sc1, int *sc2)
  57. {
  58.     if(sc1[6]<sc2[6])
  59.     {
  60.         char temp[20];
  61.         strcpy(temp,st2);
  62.         strcpy(st2,st1);
  63.         strcpy(st1,temp);
  64.         for(int i=0;i<7;i++)
  65.         {
  66.             int temp;
  67.             temp = sc2[i];
  68.             sc2[i] = sc1[i];
  69.             sc1[i] = temp;
  70.         }
  71.     }
  72. }
  73.  
  74. char char_com(char *st1, char *st2, int *sc1, int *sc2)
  75. {
  76.     if(strcmp(st1,st2)>0)
  77.     {
  78.         char temp[20];
  79.         strcpy(temp,st2);
  80.         strcpy(st2,st1);
  81.         strcpy(st1,temp);
  82.         for(int i=0;i<7;i++)
  83.         {
  84.             int temp;
  85.             temp = sc2[i];
  86.             sc2[i] = sc1[i];
  87.             sc1[i] = temp;
  88.         }
  89.     }
  90. }
  91.  
  92. void output(char (*store)[20], int (*score)[7])
  93. {
  94.     int i=0,j=0;
  95.     for(i=0;i<4;i++)
  96.     {
  97.         printf("%s  ",store[i]);
  98.         for(j=0;j<7;j++)
  99.         {
  100.             printf("%3d  ",score[i][j]);
  101.         }
  102.         printf("\n");
  103.     }
  104. }
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×