2 条题解

  • 0
    @ 2025-10-27 22:50:04
    #include<stdio.h>
    #include<string.h>
    
    int main(){
    	
    	int n;
    	scanf("%d",&n);
    	
    	int tot[100];
    	for(int i=0;i<n;i++){
    		scanf("%d",&tot[i]);
    	}
    	int count=0;
    	for(int i=0;i<n;i++)
    	{
    		for(int j=i;j<n;j++)
    		{
    			if(tot[i]>tot[j])
    			{
    				count++;
    			}	
    		}	
    	}
    	printf("%d",count);
    	
    	return 0;
    }
    
    • 0
      @ 2025-9-30 17:32:07

      骗你的,佛祖根本管不了你能不能用函数。

      如果一定要用函数的话,把中间的循环的那一部分拆出来即可。

      #include<stdio.h>
      #include<string.h>
      #include<stdlib.h>
      
      int main(){
      	int n,i,j;
      	scanf("%d",&n);
      	int count=0;
      	int a[n];
      	for(i=0;i<n;i++){
      		scanf("%d",&a[i]);
      	}
        //从这里开始拆成函数
      	for(i=0;i<n;i++){
      		for(j=i+1;j<n;j++){
      			if(a[i]>a[j]){
      				count++;
      			}
      		}
      	}
        //在这里结束
      	printf("%d",count);
      	
      	return 0;
      }
      
      • 1

      信息

      ID
      718
      时间
      1000ms
      内存
      256MiB
      难度
      1
      标签
      (无)
      递交数
      110
      已通过
      77
      上传者