1 条题解

  • 0
    @ 2024-12-24 10:06:16

    C++ :

    #include<iostream>
    #include<cstdio>
    
    using namespace std;
    int main()
    {
    	int a[10010];
    	int n,temp,ans=0;
    	cin>>n;
    	for(int i=1;i<=n;++i)
    	cin>>a[i];
    	
    	for(int i=1;i<=n;++i)
    	for(int j=1;j<=n-i;++j)
    	if(a[j]>a[j+1])
    	{
    		temp=a[j];
    		a[j]=a[j+1];
    		a[j+1]=temp;
    		ans++;
    	}
    	cout<<ans;
    	return 0;
    }
    
    • 1

    信息

    ID
    2575
    时间
    1000ms
    内存
    128MiB
    难度
    (无)
    标签
    递交数
    0
    已通过
    0
    上传者