Time Limit: 1sec Memory Limit:256MB
Description
Implement a sort function that returns a new sorted array. The function header is:
int *sort(const int * const array, int size);
Hint
Don't submit the main() function.
大家来找错:
// Problem#: 14390
// Submission#: 3726576
// The source code is licensed under Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License
// URI: http://creativecommons.org/licenses/by-nc-sa/3.0/
// All Copyright reserved by Informatic Lab of Sun Yat-sen University
#include<iostream>
using namespace std;
int *sort(const int * const array, int size){
int *a=new int [size];
memcy(a,array.size*sizeof(int));
sort(a,a+size);
return a;
}
正解:
// Problem#: 14390
// Submission#: 3726586
// The source code is licensed under Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License
// URI: http://creativecommons.org/licenses/by-nc-sa/3.0/
// All Copyright reserved by Informatic Lab of Sun Yat-sen University
#include<iostream>
#include <cstring>
#include<algorithm>
using namespace std;
int *sort(const int * const array, int size){
int *a=new int [size];
memcpy(a,array,size*sizeof(int));
sort(a,a+size);
return a;
}
conclusion: