首页 > 代码库 > HWOJ之纠结的优化

HWOJ之纠结的优化

好无力,今天改到了自认为的最优法,还能超时吗???

#include<stdio.h>#include<string.h>#define bool int //两个数据的交换void swap(int *a,int *b) {    int temp;    temp = *a;    *a = *b;    *b = temp;}//优化后的冒泡排序void bubbleSort(int *array,int arraySize) {    bool flag = 1;    int i =0;    int j =0;        while(flag) {        flag = 0;        for(j=0;j<arraySize-1-i;j++) {            if(array[j]<array[j+1]) {                swap(&array[j],&array[j+1]);                flag = 1;            }        }        i++;    }}void main() {    int inputData[100] = {0};    int outputData[100] = {0};    int t;    int p;       //数据的传入    int i = 0;    int *pOutDataHead;    int *pOutDataEnd;    do{        scanf("%d",&inputData[i]);        i++;    }while(getchar() != \n );    bubbleSort(inputData,i);    pOutDataHead = &outputData[0];    pOutDataEnd = &outputData[i-1];        //选出奇数,选出偶数    for(t = 0;t<i;t++) {        if((inputData[t]%2)!=0) {            *pOutDataHead = inputData[t];             pOutDataHead++;        }                     else {            *pOutDataEnd = inputData[t];             pOutDataEnd--;        }            }    //--------------------------    for(p=0;p<i;p++) {        printf("%d ",outputData[p]);    }    }    

 

HWOJ之纠结的优化