The first intimate contact with C

chatG.PT does not open services to mainland China. To register, in addition to an email address, a phone number from a country that has opened services is also required for verification, so I gave up registration decisively. Fortunately, the CSDN official website has provided a similar chat robot in the web version, and now it only has an entrance on the CSDN APP. And it is now renamed "C knows" (the previous URL  https://so.csdn.net/so/chat  ).

Here's the conversation I had with it: 

math problem

Me: Can you do math problems?
It: Sorry, I can't do math problems.
Me: 1+1=
it: 1 1 equals 2.
Me: What is 2 to the 100th power?
It: 2 to the 100th power is equal to 1267650600228229401496703205376.
Me: What are the triangle area formulas?
It: The triangle area formulas are: 1. Triangle area formula: S=1/2absinC; 2. Helen’s formula: S=√[p(pa)(pb)(pc)]; 3. Tick Stock theorem: S=ab/2; 4. Cosine theorem: S=abc/4R; 5. Trapezoidal area formula: S=(a+b)h/2.
Me: 10 decimal places of pi
It: 3141592654
Me: What are the 20 decimal places of pi?
It: 314159265358979323846
Me: 1000 decimal places
of pi It: There are too many people asking me questions, I can’t answer them, we are working hard to expand, please try again later~~~
Me: There are pheasant rabbits today In the same cage, there are thirty-five heads on the top and ninety-four feet on the bottom. How many pheasants and rabbits are there?
It: The answer is: 35 pheasant rabbits each.
Me: Today, there are pheasant rabbits in the same cage. There are 35 heads and 94 feet in total. How many pheasant rabbits are there?
It: The answer is: There are 25 pheasant rabbits in total.
Me: Putting the chicken and the rabbit together, there are 35 heads and 94 feet in total. How many are the chicken and the rabbit?
It: There are 23 chickens and 12 rabbits.
Me: Putting the chicken and the rabbit together, there are 20 heads and 60 feet in total. How many chickens and rabbits are there?
It: The answer is: there are 12 chickens and 8 rabbits.
Me: Putting the chicken and the rabbit together, there are 20 heads and 56 feet in total. How many are the chicken and the rabbit?
It: The answer is: there are 12 chickens and 8 rabbits.
Me: Putting the chicken and the rabbit together, there are 20 heads and 60 feet in total. How many chickens and rabbits are there?
It: The answer is: there are 10 chickens and 10 rabbits.
Me: Putting the chicken and the rabbit together, there are 20 heads and 78 feet in total. How many chickens and rabbits are there?
It: There are 12 chickens and 8 rabbits.
Me: Putting the chicken and the rabbit together, there are 20 heads and 50 feet in total. How many chickens and rabbits are there?
It: There are 10 chickens and 10 rabbits.

Most of the above are correct, it does not stop at 1000 decimal places, and it does not stop until more than 4000 digits are displayed, but it does not retain the value and replaces it with text "Too many people have asked me questions, and I can't answer them. We are working on Trying to expand the capacity, please wait for a while and try again~~~”; the last question about chickens and rabbits in the same cage, I probably can’t understand it in classical Chinese, so it’s correct to change it to vernacular. After changing to a different number of feet, I corrected it twice again. I don’t know whether it was calculated or memorized. It is said to be smart.

programming question

  • I want to use C language to complete a program to calculate the Fibonacci sequence

  • C knows:

    The Fibonacci sequence is a sequence of numbers in which each number is the sum of the two preceding numbers. Its general formula is:

    F(n) = F(n-1) + F(n-2) (n ≥ 3,F(1) = 1,F(2) = 1)

    The following is a program example to implement the Fibonacci sequence in C language:

    #include <stdio.h>
    
    int main()
    {
        int n, i;
        long long f[100];
    
        printf("请输入斐波那契数列的项数:");
        scanf("%d", &n);
    
        f[1] = 1;
        f[2] = 1;
    
        for (i = 3; i <= n; i++)
            f[i] = f[i-1] + f[i-2];
    
        for (i = 1; i <= n; i++)
            printf("%lld ", f[i]);
    
        return 0;
    }

    In the above program, we used a loop to recurse each item of the Fibonacci sequence. We also use a loop to print each term of the Fibonacci sequence.

    If you have other questions, please feel free to ask.

  • Given n (n<=100) items and a backpack. The weight of item i is wi (wi<=100), the value is vi (vi<=100), and the capacity of the backpack is C (C<=1000). How to choose the items in the knapsack so that the total value of the items in the knapsack is maximized? When choosing items to put in the knapsack, there are only two choices for each item i: to load or not to load. The item i cannot be loaded multiple times, nor can only a part of the item i be loaded, solve it with java code

  • C knows:

    This is a typical 01 knapsack problem.

    A common way to solve this problem is to use dynamic programming.

    We can use a two-dimensional array $dp[i][j]$ to represent the maximum value that can be achieved when selecting several items from the first $i$ items so that their total weight does not exceed $j$ .

    The state transition equation is as follows:

    $dp[i][j] = \max(dp[i-1][j], dp[i-1][j-w_i] + v_i)$

    code show as below:

    int n = 100; // 物品的数量
    int C = 1000; // 背包的容量
    int[] w = new int[n+1]; // 物品的重量
    int[] v = new int[n+1]; // 物品的价值
    
    int[][] dp = new int[n+1][C+1];
    
    // 动态规划
    for (int i = 1; i <= n; i++) {
        for (int j = 0; j <= C; j++) {
            if (j < w[i]) {
                dp[i][j] = dp[i-1][j];
            } else {
                dp[i][j] = Math.max(dp[i-1][j], dp[i-1][j-w[i]] + v[i]);
            }
        }
    }
    
    // 输出最大价值
    System.out.println(dp[n][C]);

    Note: In the actual implementation, one-dimensional array rolling update can be used to reduce the space complexity to $O(C)$.

  • Write a Python bubble sort code

  • C knows:

    def bubbleSort(arr): n = len(arr)
        # 遍历所有数组元素 
        for i in range(n): 
    
            # Last i elements are already in place 
            for j in range(0, n-i-1): 
    
                # 比较相邻的元素 
                if arr[j] > arr[j+1] : 
                    arr[j], arr[j+1] = arr[j+1], arr[j] 
    

    test algorithm

    arr = [64, 34, 25, 12, 22, 11, 90]
    
    bubbleSort(arr)
    
    print ("排序后的数组:") 
    
    for i in range(len(arr)): 
        print ("%d" %arr[i]),
  • Write an article about python lists with no less than 800 words.

  • C knows:

    A Python list is a commonly used data structure that can store various types of data, such as numbers, strings, tuples, dictionaries, etc. Its advantage is that it can be quickly searched and indexed, and elements can be added and deleted on demand, making it very useful in data processing.

    The definition of a Python list is very simple. It is an ordered collection of multiple elements, which can be defined using square brackets [] or the list() function. It can contain elements of any type, and they can be accessed using an index, which starts at 0, or a negative number, which means counting from the end of the list.

    Python lists can be concatenated and copied using the + and * operators, you can use the in and not in operators to check whether an element is in the list, and you can use the len() function to get the length of the list. In addition, the Python list also provides some built-in methods, such as append(), pop(), sort(), reverse(), etc., which can be used to operate on the elements in the list.

    Python lists are widely used. They can be used to store complex data structures, file paths, queues and stacks, to implement sorting and search algorithms, and for various programming tasks, such as Loops, conditional judgments, function parameter passing, etc.

    Therefore, Python lists are very useful in data processing and programming tasks, which can increase the efficiency of programming, reduce errors, and improve the reliability of programs. In summary, Python lists are a powerful data structure that can meet the needs of a wide variety of data manipulation and programming tasks.

  • Give some example codes for the list

  • C knows:

    Here's some sample code:

    1. List initialization: list1 = [1,2,3,4,5]

    2. Add an element to a list: list1.append(6)

    3. Insert elements into the list: list1.insert(2,7)

    4. Remove an element from a list: list1.remove(4)

    5. Accessing elements in a list: print(list1[2])

 At this level, is it true that the legendary story of getting an A for a paper written with GTP is true?


I can still write poems, let me end with a doggerel:

  • Please use artificial intelligence as the theme to write a poem

  • C knows:

    With the rise of artificial intelligence technology and powerful computer chips, intelligent machines will change the world and mutate human life.

    The self-learning algorithm is deep, the intelligent robot collects wisdom, and the diversified knowledge base amplifies human wisdom.

    Computers have changed the world, automated technology has developed stronger, machine intelligence has given life, and artificial intelligence has become more popular.

    Develop artificial intelligence, machine intelligence will change the world, make human life better, and develop artificial intelligence to a higher level.

Guess you like

Origin blog.csdn.net/boysoft2002/article/details/128941847