#36045: 為啥我的bubble sort 不能用???救救我嗚嗚嗚


wheat20131@gmail.com (後為什麼又TLE啦:()

學校 : 高雄市立三民高級中學
編號 : 218090
來源 : [61.227.12.205]
最後登入時間 :
2025-04-09 18:42:37

#include <iostream>

using namespace std;

int main()
{
    int a;
    while(cin >> a){
        int b[a];
        for(int x= 0; x< a;x++){
            cin >> b[x];
        }
        for(int i = 0; i < a-1;i++){
            for(int j = 0; j < a-1; j++){
                if(b[j] > b[j+1]){
                    b[j] = b[j]+b[j+1];
                    b[j+1] = b[j]-b[j+1];
                    b[j] = b[j]-b[j+1];
                }
            }
        }
        for(int i = 0; i < a; i++){
            cout << b[i] << " ";
        }
        cout << endl;
    }
    return 0;
}

#36048: Re: 為啥我的bubble sort 不能用???救救我嗚嗚嗚


cges30901 (cges30901)

學校 : 不指定學校
編號 : 30877
來源 : [39.12.66.21]
最後登入時間 :
2025-04-20 17:19:22

#include

using namespace std;

int main()
{
    int a;
    while(cin >> a){
        int b[a];
        for(int x= 0; x< a;x++){
            cin >> b[x];
        }
        for(int i = 0; i < a-1;i++){
            for(int j = 0; j < a-1; j++){
                if(b[j] > b[j+1]){
                    b[j] = b[j]+b[j+1];
                    b[j+1] = b[j]-b[j+1];
                    b[j] = b[j]-b[j+1];
                }
            }
        }
        for(int i = 0; i < a; i++){
            cout << b[i] << " ";
        }
        cout << endl;
    }
    return 0;
}


我送出是AC?