c語言 面試題


     

     //經典7dom

    //星期一   Mondayide

    //星期二   Tuesdayspa

    //星期三   Wednesdaycode

    //星期四   Thursdayget

    //星期五   Fridayit

    //星期六   Saturdayclass

    //星期日   sundaystream

    //請輸入星期幾的第一個字母來判斷一下是星期幾,若是第一個字母同樣,則繼續判斷第二個字母float

    char week1;di

    char week2;

    printf("星期一   Monday \n星期二   Tuesday \n星期三   

Wednesday  \n星期四   Thursday  \n星期五   Friday  \n星期六   Saturday   \n星期日   

sunday\nplease enter a letter\n");

    scanf("%c",&week1);

    switch(week1)

    {

        case('M' 'm'):printf("the answer is Monday\n");

            break;

        case'W':printf("the answer is Wednesday\n");

            break;

        case('F' 'f'):printf("the answer is Friday\n");

            break;

       case('S' 's'):

        {

            printf("please enter the second letter\n");

            scanf("%c",&week2);

            getchar();

            if(week2 == ('a' 'A'))

                printf("the answer is Saturday\n");

            else

                if(week2 == ('u' 'U'))

                    printf("the answer is Sunday\n");

                else

                    printf("there is no answer\n");

        }

            break;

        case('T' 't'):

        {

            printf("please enter the second letter\n");

            scanf("%c",&week2);

            getchar();

            if(week2 == ('U' 'u'))               printf("the answer is Tuesday\n");

            else               if(week2 == ('H' 'h'))

                printf("the answer is Thursday\n");

            else

              printf("there is no answer\n");

        }

            break;

        default:

            printf("there is no correct answer\n");

            break;

    }

     

    // 經典8

    //有1000000個數,每一個數取值範圍是0-999999找出其中重複的數,重複次數

    int a[1000000] = {0}, b[1000000] = {0}, count = 0;

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

        a[i] = arc4random()%1000000;

        b[a[i]]++;

    }

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

        if(b[j] > 1){

            count++;

            printf("重複數是%d \n",j);

        }

    }

相關文章
相關標籤/搜索