Array name as function argument

Recently, the teacher is going to have an open class for freshman. We also reviewed C
Knowledge points of language:


A city has been attacked by COVID-19, and the whole city has closed the district management. "One side is in trouble and all sides support". Brother provinces and cities have donated a large number of living materials to them, which are regularly distributed by the community to the residents of each community. In order to better serve the residents, the caring community volunteers first inform the residents of the list of materials (10 kinds), and the residents fill in the materials they need online (limited to 3 kinds and below), and then the volunteers pack them and give them to the residents.
In the packaging process, because different types of materials may be placed far away, volunteers need to run far to select and package the three materials together. Smart Xiao Wu found that many people have the same material combination in their needs. If these combined materials are placed together during unloading, it can save some labor for the hard-working volunteers. Please help out these often together material demand combinations. (there are 498 families in the community).
The specific data is not stuck. There are a lot of data. There are 498 families in total. Each family needs less than three kinds of materials. For convenience, we can count the matching of the two materials with the most times at the same time, so that we can put them in the same place and save more manpower and material resources. Today's code is to complete such a thing.


//Code for direct character processing 
#define SValue 40
//Function to return the number of frequently combined groups frequentNum
int freCom(char mL[10][10],char wL[500][3][10],char cL[45][2][10])
	//Declare a function to determine whether it is the number of frequently occurring groups
    int freJudge(char mat1[10],char mat2[10],char wL[500][3][10]);
    //Declaring functions, copying strings
    void copyStr(char t[10],char s[10]);
    int frequentNum=0;//A variable that records the number of frequent occurrences 
    int i,j;
    for(i=0; i<10; i++)
        for(j=i+1; j<10; j++)
    return frequentNum;
//Copy string 
void copyStr(char t[10],char s[10])
    int i=0;
int freJudge(char mat1[10],char mat2[10],char wL[500][3][10])
	//Declare whether it belongs to the function 
    int isBelong(char subStr[10],char sourceStr[3][10]);
    int i=0,beCount=0;
           beCount++;//If both strings belong to that line of character set at the same time, beCount plus one 
        return 1;//In 500 records, if the number of times is greater than 40, it returns 1, indicating that it is a frequent combination
        return 0;//Otherwise, it returns 0, indicating that it is not a frequent combination 
//Determine whether the subStr string belongs to the sourceStr string set 
int isBelong(char subStr[10],char sourceStr[3][10])
    int i,j;
    int sign;
            return 1;
    return 0;

This section mainly uses the array name as the function argument to solve the practical problems. Our processing method is to directly use the string processing code to make the materials needed by 500 residents into a three-dimensional array and directly compare the strings. In 500 records, if the number of times is greater than 40, it means that it is a frequent combination. Four functions are used in the code:

 int freCom(char mL[10][10],char wL[500][3][10],char cL[45][2][10])//Returns the number of frequently combined groups frequentNum 
int freJudge(char mat1[10],char mat2[10],char wL[500][3][10]);//Judge whether there are frequent combinations. If yes, return 1; otherwise, return 0
void copyStr(char t[10],char s[10]);//Copy string
int isBelong(char subStr[10],char sourceStr[3][10])//Judge whether subStr belongs to sourceStr

It is the name of the array that is directly invoked. It is called in the main function, and it also calls other functions in the function, which makes the hierarchy of the main function more clear and clear.

Tiktok tiktok: actually, there are many ways to use this method in real life. We can expand to Taobao, jitter and other platforms. Suppose that on the short video platform, when you watch the same type of video, big data will analyze and screen people who usually watch this video. What other types or similar content will he see will be recommended to you on the homepage. There are also many such examples in daily life: for example, the person who buys toothpaste has a high probability that he will buy a toothbrush, so they often put them together. If they buy Shower Gel, they are likely to buy shampoo. There are also classic examples in foreign countries. There must be beer next to diapers. The code we wrote today is a screening process, showing the vegetables with the highest selection rate, putting them together, and then recommending them to users, which greatly saves the waste of time and space.

Tags: C array

Posted on Fri, 15 Oct 2021 23:20:42 -0400 by Ashh RA