注意!请在本地运行代码!(看着超级爽,也可以用来解压放松)
#include <bits/stdc++.h>
using namespace std ;
const int N=1000010 ;
int arr[N],n=1e6 ;
void read (int &x) //抄的
{
x = 0; bool f = 0; char ch = getchar();
while (!isdigit (ch)) f ^= !(ch ^ 45), ch = getchar();
while (isdigit (ch)) x = (x << 1) + (x << 3) + (ch & 15), ch = getchar();
x = f ? -x : x;
}
void random_data()
{
freopen("data.in","w",stdout) ;
for(int i=1;i<=n;i++)
printf("%d ",rand()*rand()) ;
fclose(stdout) ;
}
void test_unstable_sort()
{
freopen("data.in","r",stdin) ;
freopen("data.out","w",stdout) ;
for(int i=1;i<=n;i++) read(arr[i]) ;
int st=clock() ;
sort(arr+1,arr+n+1) ;
int ed=clock() ;
cerr << "unstable sort use " << double(ed-st)/1000 << " seconds!\n" ;
for(int i=1;i<=n;i++) printf("%d ",arr[i]) ;
fclose(stdin) ;
fclose(stdout) ;
}
void test_stable_sort()
{
freopen("data.in","r",stdin) ;
freopen("data.out","w",stdout) ;
for(int i=1;i<=n;i++) read(arr[i]) ;
int st=clock() ;
stable_sort(arr+1,arr+n+1) ;
int ed=clock() ;
cerr << "stable sort use " << double(ed-st)/1000 << " seconds!\n" ;
for(int i=1;i<=n;i++) printf("%d ",arr[i]) ;
fclose(stdin) ;
fclose(stdout) ;
}
int main()
{
random_data() ;
test_unstable_sort() ;
test_stable_sort() ;
return 0 ;
}
…好复杂咋 不好调啊这看起来 这要出bug咋办
我自己调试过的,没有bug,要不你试试在Dev-C++上跑一下