#include <stdio.h>
#include <stdlib.h>
int compare( const int *arg1, const int *arg2 );
int main(int argc, char *argv[])
{
    int i, j;
    int ret;
    int a[6], count[7];
    int bingo[6], cc;
    FILE* stream;
 
    for (i = 6; i >= 0; i--)
        count[i] = 0;
 
    printf("Bingo numbers:");
    scanf("%2d %2d %2d %2d %2d %2d", &bingo[0], &bingo[1], &bingo[2], &bingo[3], &bingo[4], &bingo[5])
    qsort(bingo, 6, sizeof(int), compare);
 
    stream=fopen("lotto.txt", "r");
    ret=fscanf(stream,"%2d %2d %2d %2d %2d %2d\n", &a[0], &a[1], &a[2], &a[3], &a[4], &a[5])
 
    while (ret == 6)
    {     
        qsort(a, 6, sizeof(int), compare);
        printf("%2d %2d %2d %2d %2d %2d\n",a[0], a[1], a[2], a[3], a[4], a[5])
        //compare two array
        cc = 0;
        for (i=0, j=0; i<6 && j <6; )
        {
            if (bingo[i] a[j])
            {
               cc++;
               i++; j++;    
            }
            else if (bingo[i]   a[j])
                j++;
            else
                i++;       
        }
        count[cc]++;
        ret=fscanf(stream,"%2d %2d %2d %2d %2d %2d\n",
                &a[0], &a[1], &a[2], &a[3], &a[4], &a[5]);
    }
    fclose(stream);
    for (i = 6; i >= 0; i--)
        printf("Match %d numbers: %d \n", i, count[i]);
    return 0;
}
int compare( const int *arg1, const int *arg2 )
{
    return *arg1-*arg2;
}

bookmark bookmark bookmark bookmark bookmark bookmark bookmark bookmark bookmark

Tags: , ,

This entry was posted on 星期三, 十一月 28th, 2012 at 10:42:54 and is filed under 101(上)程式設計(一). You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.

10 Trackbacks/Pings

  1. duane    七月 30 2014 / 1下午:

    rivets@beige.sumner” rel=”nofollow”>.…

    tnx for info….

  2. howard    八月 22 2014 / 5下午:

    kemm@revivalism.masonry” rel=”nofollow”>.…

    спс за инфу!…

  3. Erik    八月 23 2014 / 4下午:

    leaf@sings.stinging” rel=”nofollow”>.…

    спс….

  4. mathew    一月 21 2015 / 12上午:

    scars@socked.downgrade” rel=”nofollow”>.…

    tnx for info!!…

  5. Mitchell    一月 29 2015 / 5下午:

    shires@blaze.kennan” rel=”nofollow”>.…

    ñýíêñ çà èíôó!!…

  6. Curtis    一月 29 2015 / 6下午:

    wt@indemnity.forgetfulness” rel=”nofollow”>.…

    ñïñ….

  7. Dale    一月 31 2015 / 12下午:

    impresses@linville.dexters” rel=”nofollow”>.…

    ñïàñèáî çà èíôó….

  8. Reginald    二月 02 2015 / 12上午:

    credits@thighs.presaged” rel=”nofollow”>.…

    ñýíêñ çà èíôó….

  9. daniel    二月 02 2015 / 1上午:

    japs@telli.myras” rel=”nofollow”>.…

    ñïàñèáî….

  10. theodore    二月 02 2015 / 1上午:

    merner@experimenter.lowlands” rel=”nofollow”>.…

    ñïñ!!…

Leave a reply

Name (*)
Mail (will not be published) (*)
URI
Comment