#26069: 請各位檢查錯誤


jay940721 (柚)

學校 : 國立宜蘭大學
編號 : 158353
來源 : [61.56.165.149]
最後登入時間 :
2024-04-21 00:55:07
a225. 明明愛排列 | From: [61.58.108.137] | 發表日期 : 2021-07-15 12:20

#include <stdio.h>

#include <string.h>

 

void smain(int);

void swi(int*,int*);

int main()

{

    int input;

    while (scanf("%d",&input)!=EOF)

    {

        smain(input);

        setbuf(stdin,NULL);

    }

    return 0;

}

void smain(int input)

{

    int math[input],chack[input];

        for(int i=0;i<input;i++)

        {

         scanf("%d",&math[i]);

         chack[i]=math[i]%10;

        }

        for (int i=0;i<input;i++)

        {

            for(int j=0;j<input-i;j++)

            {

                if(chack[j]>chack[j+1])

                {

                    swi(&chack[j+1],&chack[j]);

                    swi(&math[j+1],&math[j]);

                }

                else if(chack[j+1]==chack[j]&&math[j+1]>math[j])

                {

                    swi(&math[j+1],&math[j]);

                }

            }

        }

        for (int i=0;i<input;i++)

        {

            printf("%d ",math[i]);

        }

        printf("\n");

}

void swi(int *a,int *b)

{

    int temp=*a;

         *a=*b;

         *b=temp;

}

我自己檢查顯示出的答案沒有發現問題,但在這裡測試答案錯誤,請各位幫小弟找BUG

 
#26071: Re:請各位檢查錯誤


vic20050418@gmail.com (Wen Vic)

學校 : 國立臺灣科技大學
編號 : 153262
來源 : [114.136.159.95]
最後登入時間 :
2023-07-29 13:10:41
a225. 明明愛排列 | From: [223.137.45.57] | 發表日期 : 2021-07-15 12:38

 

7

38 106 98 26 13 46 51

32766 51 13 106 46 26 98

6

1 2 3 4 5 0

0 1 2 3 4 5

5

98 76 12 34 55

0 12 34 55 76

6

33 33 88 88 83 38

83 33 33 88 88 38

我拿你程式碼下去測 全錯啊 你要不要重寫??

你可能要在想一下 重寫吧 太長了...

 
ZeroJudge Forum