• gravity2


    #include <stdio.h>
    #include <stdlib.h>
    
    int test_main(int data[100]);
    int test_main(int data[100])
    {
        int count=0;
        int max=0;
        int z=0;
        for(int i=0;i<100;i++){
            for(int j=i+1;j<100;j++){
                if(data[i]<=data[j])z++;
                if(data[i]>data[j]){
                    count=j-i-z;
                    if(count>max)max=count;
                }
            }
            count =0;
            z=0;
        }
        
    
        return max; //return a value of ‘fall head’ of the box which will have the largest ‘fall head’ after rotating and being affected by gravity.
    }
    
    
    
    void build_data(int data[100])
    {
        for (int i = 0; i < 100; i++)
        {
            data[i] = rand() % 101; 
        }
    }
    
    
    
    void main(void)
    {
        int data[100];
    
        for (int l = 0; l < 10; l++)
        {
            build_data(data);
            printf("%d
    ", test_main(data));
        }
    }
  • 相关阅读:
    字符串、组合练习
    national flag
    常用的Linux操作
    大数据概述
    LL(1)文法
    简单有穷自动机
    简单C语言文法
    词法分析
    编译原理 141
    综合练习
  • 原文地址:https://www.cnblogs.com/ZzznOoooo/p/6628071.html
Copyright © 2020-2023  润新知