Archive for 十一月, 2013

1127prog

排序演算法的複雜度

排序演算法的複雜度

比對演算法的複雜度

比對演算法的複雜度

bookmark bookmark bookmark bookmark bookmark bookmark bookmark bookmark bookmark

Tags: , ,

27
十一月

程式設計一程式 11/27: ex10.c

   Posted by: admin    in 102(上)程式設計(一)

int main(int argc, char *argv[])
{
    int i, j, count;
    int bingo[6];
    int num[6], yescount;
    FILE* in;
 
    srand( (unsigned) time( NULL ) );//設定亂數的啟始點
 
    NumGen(bingo);
    //排序
    qsort(bingo, 6, sizeof(int), compare );
    printf("The bingo numbers: %2d %2d %2d %2d %2d %2d\n", 
                bingo[0], bingo[1], bingo[2], bingo[3], bingo[4], bingo[5]);
 
    in = fopen("lotto.txt", "r");
    count = fscanf(in, "%d %d %d %d %d %d\n", &num[0], &num[1], &num[2], &num[3], &num[4], &num[5]); 
    while (count == 6)
    {
          yescount = 0;
          for (i=0, j=0; i< 6, j<6; )
          {
              if (num[i] < bingo[j])
                 i++;
              else if (num[i] > bingo[j])
                 j++;
              else
              {
                  yescount++;
                  i++; j++;
              }
          }
          printf("%2d %2d %2d %2d %2d %2d= %d \n", num[0], num[1], num[2], num[3], num[4], num[5], yescount);
          count = fscanf(in, "%d %d %d %d %d %d\n", &num[0], &num[1], &num[2], &num[3], &num[4], &num[5]);
    }
 
    fclose(in);
    return 0;
}

bookmark bookmark bookmark bookmark bookmark bookmark bookmark bookmark bookmark

Tags: , ,

27
十一月

資訊與生活上課 11/22 個人電腦介紹

   Posted by: admin    in 102(上)資訊與科技

1122it

電腦組成元件介紹

電腦組成元件介紹

 

bookmark bookmark bookmark bookmark bookmark bookmark bookmark bookmark bookmark

Tags: , ,

20
十一月

程式設計一程式 11/20: ex9.c

   Posted by: admin    in 102(上)程式設計(一)

void NumGen(int num[]);
int compare( const int *arg1, const int *arg2 );
int main(int argc, char *argv[])
{
    int n, i, j, tickets;
    int num[6], tmp;
    FILE* out;
    tickets = atoi(argv[1]);
    srand( (unsigned) time( NULL ) );//設定亂數的啟始點
 
    out = fopen("lotto.txt", "w");
    for (n=0; n< tickets; n++)
    {
        //NumGen(num);
        //排序
        //qsort(num, 6, sizeof(int), compare );
        //printf("%2d %2d %2d %2d %2d %2d\n", num[0], num[1], num[2], num[3], num[4], num[5]);
        //fprintf(out, "%2d %2d %2d %2d %2d %2d\n", num[0], num[1], num[2], num[3], num[4], num[5]);
    }
    fclose(out);
    return 0;
}
void NumGen(int num[])
{
    int i,j, max, select;
    int ball[49];
    for (i= 0; i< 49; i++)
    {
        ball[i] = rand();
    }
 
    for (i= 0; i< 6; i++)
    {
        select = 0;//選擇的球 
        max = ball[0];//最重的球
        for (j = 1; j < 49; j++)
        {
            if (ball[j] > max)
            {
                  max =  ball[j];  
                  select = j;  
            } 
        } 
       num[i] = select +1;//最重的那顆球編號 
            ball[select] = 0;
    }
}
int compare( const int *arg1, const int *arg2 )
{
    return *arg2-*arg1;
}

bookmark bookmark bookmark bookmark bookmark bookmark bookmark bookmark bookmark

Tags: , ,

20
十一月

程式設計一上課 11/20: 排序

   Posted by: admin    in 102(上)程式設計(一)

1120prog

bubble sort

bubble sort

使用qsort()函數

使用qsort()函數

bookmark bookmark bookmark bookmark bookmark bookmark bookmark bookmark bookmark

Tags: , ,