文心一言4.0 turbo VS ChatGPT-4o 深度测评

SoruxGPT
发布于 2024-08-25 / 13 阅读
2

文心一言4.0 turbo VS ChatGPT-4o 深度测评

文心一言4.0 turbo VS ChatGPT-4o

在人工智能的浩瀚星空中,两大璀璨新星——文心一言4.0 Turbo与ChatGPT-4o正引领着技术革命的新浪潮。这两款顶尖模型,各自携带着创新的光芒,为我们描绘了一幅幅智能生活的未来图景。今天,就让我们一同走进这场巅峰对决,探索它们如何以非凡的能力重塑我们的世界。

文心一言4.0 Turbo:中文世界的智慧引擎

文心一言4.0 Turbo,作为百度AI技术的集大成者,自诞生以来便以卓越的中文处理能力闻名遐迩。它不仅在文本生成、诗词创作、故事生成等领域展现出了非凡的创造力,更在用户体验上实现了全面升级。特别是其上下文输入长度的巨大提升,从2K tokens跃升至128K tokens,让文心一言能够轻松应对海量信息输入,无论是长篇文件还是复杂网页,都能快速准确理解用户意图,给出精准智能的答复。此外,文心一言在图像处理能力上的显著进步,也让其应用场景更加广泛,从视觉识别到图像处理,无所不能。

文心一言4.0 Turbo的发布,不仅标志着百度在AI领域的又一次飞跃,更彰显了其在中文智能服务市场的领先地位。凭借其深厚的中文底蕴和强大的技术实力,文心一言正逐步成为亿万中文用户信赖的智慧伙伴。

ChatGPT-4o:多模态交互的新纪元

另一边,ChatGPT-4o作为OpenAI的最新旗舰模型,自发布以来便备受瞩目。它继承了ChatGPT系列的优秀基因,并在此基础上实现了质的飞跃。ChatGPT-4o的最大亮点在于其多模态处理能力,能够实时处理和生成文本、音频以及图像等多种模态的数据,为用户提供更全面、更丰富的交互体验。这种跨模态的能力使得ChatGPT-4o在复杂场景下的应用更加得心应手,无论是图像分析、语音识别还是自然语言处理,都能游刃有余。

此外,ChatGPT-4o还显著提升了实时推理能力,能够更快速、更准确地响应用户的复杂查询和需求。这种高效的响应速度不仅提升了用户体验,也为AI在更多领域的应用提供了可能。ChatGPT-4o的发布,标志着OpenAI在多模态交互技术上的重大突破,也预示着人工智能即将进入一个全新的发展阶段。

1.写一个快速排序

文心一言给出的答案:

public class QuickSort {  
    public static void quickSort(int[] arr, int low, int high) {  
        if (low < high) {  
            // pi是分区索引,arr[pi]现在放在了正确的位置  
            int pi = partition(arr, low, high);  
  
            // 递归排序元素在分区索引之前和之后的元素  
            quickSort(arr, low, pi - 1);  
            quickSort(arr, pi + 1, high);  
        }  
    }  
  
    // 这个函数负责分区操作,它选择最后一个元素作为基准,并将小于基准的元素放在基准之前,大于基准的放在基准之后  
    private static int partition(int[] arr, int low, int high) {  
        int pivot = arr[high];  
        int i = (low - 1); // 较小元素的索引  
  
        for (int j = low; j < high; j++) {  
            // 如果当前元素小于或等于pivot  
            if (arr[j] <= pivot) {  
                i++;  
  
                // 交换 arr[i] 和 arr[j]  
                int temp = arr[i];  
                arr[i] = arr[j];  
                arr[j] = temp;  
            }  
        }  
  
        // 交换 arr[i+1] 和 arr[high] (或pivot)  
        int temp = arr[i + 1];  
        arr[i + 1] = arr[high];  
        arr[high] = temp;  
  
        return i + 1;  
    }  
  
    /* 用于打印数组 */  
    static void printArray(int[] arr) {  
        for (int i = 0; i < arr.length; i++) {  
            System.out.print(arr[i] + " ");  
        }  
        System.out.println();  
    }  
  
    // 测试代码  
    public static void main(String args[]) {  
        int[] arr = {10, 7, 8, 9, 1, 5};  
        int n = arr.length;  
  
        quickSort(arr, 0, n - 1);  
  
        System.out.println("Sorted array: ");  
        printArray(arr);  
    }  
}

ChatGPT给出的答案:

public class QuickSort {
​
    // 主方法
    public static void main(String[] args) {
        int[] array = { 34, 7, 23, 32, 5, 62, 32, 7 };
​
        System.out.println("排序前:");
        printArray(array);
​
        quickSort(array, 0, array.length - 1);
​
        System.out.println("排序后:");
        printArray(array);
    }
​
    // 快速排序方法
    public static void quickSort(int[] array, int low, int high) {
        if (low < high) {
            int pivotIndex = partition(array, low, high); // 获取基准元素索引
            quickSort(array, low, pivotIndex - 1);  // 对基准元素左边部分排序
            quickSort(array, pivotIndex + 1, high); // 对基准元素右边部分排序
        }
    }
​
    // 分区方法
    public static int partition(int[] array, int low, int high) {
        int pivot = array[high]; // 选择最右边的元素作为基准
        int i = low - 1; // i 是较小元素的索引
​
        for (int j = low; j < high; j++) {
            if (array[j] < pivot) {
                i++;
                swap(array, i, j); // 交换 array[i] 和 array[j]
            }
        }
​
        swap(array, i + 1, high); // 把基准元素放到正确的位置
        return i + 1; // 返回基准元素的位置
    }
​
    // 交换数组中的两个元素
    public static void swap(int[] array, int i, int j) {
        int temp = array[i];
        array[i] = array[j];
        array[j] = temp;
    }
​
    // 打印数组
    public static void printArray(int[] array) {
        for (int num : array) {
            System.out.print(num + " ");
        }
        System.out.println();
    }
}

从效率上来看是差不多的

接下来试一试长代码能力

2.写一颗红黑树,实现增删改查功能

ChatGPT给出的答案:

public class RedBlackTree<T extends Comparable<T>> {
​
    private static final boolean RED = true;
    private static final boolean BLACK = false;
​
    private class Node {
        T data;
        Node left, right, parent;
        boolean color;
​
        Node(T data) {
            this.data = data;
            this.color = RED;
        }
    }
​
    private Node root;
​
    // 插入操作
    public void insert(T data) {
        Node newNode = new Node(data);
        root = insert(root, newNode);
        fixAfterInsert(newNode);
    }
​
    // 插入节点的辅助方法
    private Node insert(Node root, Node newNode) {
        if (root == null) {
            return newNode;
        }
        int cmp = newNode.data.compareTo(root.data);
        if (cmp < 0) {
            root.left = insert(root.left, newNode);
            root.left.parent = root;
        } else if (cmp > 0) {
            root.right = insert(root.right, newNode);
            root.right.parent = root;
        }
        return root;
    }
​
    // 插入后修正树平衡
    private void fixAfterInsert(Node node) {
        while (node != null && node != root && node.parent.color == RED) {
            if (parentOf(node) == leftOf(parentOf(parentOf(node)))) {
                Node uncle = rightOf(parentOf(parentOf(node)));
                if (colorOf(uncle) == RED) {
                    setColor(parentOf(node), BLACK);
                    setColor(uncle, BLACK);
                    setColor(parentOf(parentOf(node)), RED);
                    node = parentOf(parentOf(node));
                } else {
                    if (node == rightOf(parentOf(node))) {
                        node = parentOf(node);
                        rotateLeft(node);
                    }
                    setColor(parentOf(node), BLACK);
                    setColor(parentOf(parentOf(node)), RED);
                    rotateRight(parentOf(parentOf(node)));
                }
            } else {
                Node uncle = leftOf(parentOf(parentOf(node)));
                if (colorOf(uncle) == RED) {
                    setColor(parentOf(node), BLACK);
                    setColor(uncle, BLACK);
                    setColor(parentOf(parentOf(node)), RED);
                    node = parentOf(parentOf(node));
                } else {
                    if (node == leftOf(parentOf(node))) {
                        node = parentOf(node);
                        rotateRight(node);
                    }
                    setColor(parentOf(node), BLACK);
                    setColor(parentOf(parentOf(node)), RED);
                    rotateLeft(parentOf(parentOf(node)));
                }
            }
        }
        root.color = BLACK;
    }
​
    // 左旋转
    private void rotateLeft(Node node) {
        if (node != null) {
            Node right = node.right;
            node.right = right.left;
            if (right.left != null)
                right.left.parent = node;
            right.parent = node.parent;
            if (node.parent == null)
                root = right;
            else if (node.parent.left == node)
                node.parent.left = right;
            else
                node.parent.right = right;
            right.left = node;
            node.parent = right;
        }
    }
​
    // 右旋转
    private void rotateRight(Node node) {
        if (node != null) {
            Node left = node.left;
            node.left = left.right;
            if (left.right != null) left.right.parent = node;
            left.parent = node.parent;
            if (node.parent == null) root = left;
            else if (node.parent.right == node) node.parent.right = left;
            else node.parent.left = left;
            left.right = node;
            node.parent = left;
        }
    }
​
    // 删除操作
    public void delete(T data) {
        Node node = search(root, data);
        if (node != null) {
            deleteNode(node);
        }
    }
​
    // 删除节点的辅助方法
    private void deleteNode(Node node) {
        if (node.left != null && node.right != null) {
            Node successor = minimum(node.right);
            node.data = successor.data;
            node = successor;
        }
​
        Node replacement = (node.left != null) ? node.left : node.right;
​
        if (replacement != null) {
            replacement.parent = node.parent;
            if (node.parent == null) {
                root = replacement;
            } else if (node == node.parent.left) {
                node.parent.left = replacement;
            } else {
                node.parent.right = replacement;
            }
            node.left = node.right = node.parent = null;
​
            if (node.color == BLACK) {
                fixAfterDelete(replacement);
            }
        } else if (node.parent == null) {
            root = null;
        } else {
            if (node.color == BLACK) {
                fixAfterDelete(node);
            }
​
            if (node.parent != null) {
                if (node == node.parent.left) {
                    node.parent.left = null;
                } else if (node == node.parent.right) {
                    node.parent.right = null;
                }
                node.parent = null;
            }
        }
    }
​
    // 删除后修正树平衡
    private void fixAfterDelete(Node node) {
        while (node != root && colorOf(node) == BLACK) {
            if (node == leftOf(parentOf(node))) {
                Node sibling = rightOf(parentOf(node));
​
                if (colorOf(sibling) == RED) {
                    setColor(sibling, BLACK);
                    setColor(parentOf(node), RED);
                    rotateLeft(parentOf(node));
                    sibling = rightOf(parentOf(node));
                }
​
                if (colorOf(leftOf(sibling)) == BLACK && colorOf(rightOf(sibling)) == BLACK) {
                    setColor(sibling, RED);
                    node = parentOf(node);
                } else {
                    if (colorOf(rightOf(sibling)) == BLACK) {
                        setColor(leftOf(sibling), BLACK);
                        setColor(sibling, RED);
                        rotateRight(sibling);
                        sibling = rightOf(parentOf(node));
                    }
                    setColor(sibling, colorOf(parentOf(node)));
                    setColor(parentOf(node), BLACK);
                    setColor(rightOf(sibling), BLACK);
                    rotateLeft(parentOf(node));
                    node = root;
                }
            } else {
                Node sibling = leftOf(parentOf(node));
​
                if (colorOf(sibling) == RED) {
                    setColor(sibling, BLACK);
                    setColor(parentOf(node), RED);
                    rotateRight(parentOf(node));
                    sibling = leftOf(parentOf(node));
                }
​
                if (colorOf(rightOf(sibling)) == BLACK && colorOf(leftOf(sibling)) == BLACK) {
                    setColor(sibling, RED);
                    node = parentOf(node);
                } else {
                    if (colorOf(leftOf(sibling)) == BLACK) {
                        setColor(rightOf(sibling), BLACK);
                        setColor(sibling, RED);
                        rotateLeft(sibling);
                        sibling = leftOf(parentOf(node));
                    }
                    setColor(sibling, colorOf(parentOf(node)));
                    setColor(parentOf(node), BLACK);
                    setColor(leftOf(sibling), BLACK);
                    rotateRight(parentOf(node));
                    node = root;
                }
            }
        }
​
        setColor(node, BLACK);
    }
​
    // 查找操作
    public boolean contains(T data) {
        return search(root, data) != null;
    }
​
    // 查找节点的辅助方法
    private Node search(Node root, T data) {
        while (root != null) {
            int cmp = data.compareTo(root.data);
            if (cmp < 0) {
                root = root.left;
            } else if (cmp > 0) {
                root = root.right;
            } else {
                return root;
            }
        }
        return null;
    }
​
    // 获取最小值节点
    private Node minimum(Node node) {
        while (node.left != null) {
            node = node.left;
        }
        return node;
    }
​
    // 辅助方法:获取节点的颜色
    private boolean colorOf(Node node) {
        return node == null ? BLACK : node.color;
    }
​
    // 辅助方法:设置节点的颜色
    private void setColor(Node node, boolean color) {
        if (node != null) {
            node.color = color;
        }
    }
​
    // 辅助方法:获取父节点
    private Node parentOf(Node node) {
        return node == null ? null : node.parent;
    }
​
    // 辅助方法:获取左子节点
    private Node leftOf(Node node) {
        return node == null ? null : node.left;
    }
​
    // 辅助方法:获取右子节点
    private Node rightOf(Node node) {
        return node == null ? null : node.right;
    }
​
    // 打印树的结构(用于调试)
    public void printTree() {
        printTree(root, "", true);
    }
​
    private void printTree(Node node, String indent, boolean last) {
        if (node != null) {
            System.out.print(indent);
            if (last) {
                System.out.print("R----");
                indent += "   ";
            } else {
                System.out.print("L----");
                indent += "|  ";
            }
            String color = node.color == RED ? "RED" : "BLACK";
            System.out.println(node.data + "(" + color + ")");
            printTree(node.left, indent, false);
            printTree(node.right, indent, true);
        }
    }
​
    public static void main(String[] args) {
        RedBlackTree<Integer> rbTree = new RedBlackTree<>();
        rbTree.insert(10);
        rbTree.insert(20);
        rbTree.insert(30);
        rbTree.insert(15);
        rbTree.insert(25);
​
        rbTree.printTree();
​
        System.out.println("\n删除 20:");
        rbTree.delete(20);
        rbTree.printTree();
​
        System.out.println("\n查找 25: " + rbTree.contains(25));
        System.out.println("查找 20: " + rbTree.contains(20));
    }
}

文心一言给出的答案:

class Node {  
    int data;  
    Node left, right, parent;  
    boolean color; // true for Red, false for Black  
  
    Node(int data) {  
        this.data = data;  
        left = null;  
        right = null;  
        parent = null;  
        color = true; // 新节点默认为红色  
    }  
}  
  
public class RedBlackTree {  
    private Node root;  
  
    public RedBlackTree() {  
        root = null;  
    }  
  
    // 插入新值  
    public void insert(int data) {  
        Node newNode = new Node(data);  
        if (root == null) {  
            root = newNode;  
        } else {  
            insertRec(root, newNode);  
        }  
        fixViolation(newNode);  
    }  
  
    private void insertRec(Node root, Node newNode) {  
        if (newNode.data < root.data) {  
            if (root.left == null) {  
                root.left = newNode;  
                newNode.parent = root;  
            } else {  
                insertRec(root.left, newNode);  
            }  
        } else if (newNode.data > root.data) {  
            if (root.right == null) {  
                root.right = newNode;  
                newNode.parent = root;  
            } else {  
                insertRec(root.right, newNode);  
            }  
        }  
    }  
  
    // 删除节点  
    public void delete(int data) {  
        Node nodeToDelete = root;  
        Node parent = null;  
        boolean isLeftChild = true;  
  
        while (nodeToDelete != null && nodeToDelete.data != data) {  
            parent = nodeToDelete;  
            if (data < nodeToDelete.data) {  
                nodeToDelete = nodeToDelete.left;  
                isLeftChild = true;  
            } else {  
                nodeToDelete = nodeToDelete.right;  
                isLeftChild = false;  
            }  
        }  
  
        if (nodeToDelete == null) {  
            return;  
        }  
  
        deleteNode(nodeToDelete, parent, isLeftChild);  
    }  
  
    private void deleteNode(Node nodeToDelete, Node parent, boolean isLeftChild) {  
        if (nodeToDelete.left == null || nodeToDelete.right == null) {  
            Node replacement = nodeToDelete.left != null ? nodeToDelete.left : nodeToDelete.right;  
  
            if (replacement != null) {  
                replacement.parent = parent;  
                if (parent == null) {  
                    root = replacement;  
                } else if (isLeftChild) {  
                    parent.left = replacement;  
                } else {  
                    parent.right = replacement;  
                }  
  
                nodeToDelete.left = nodeToDelete.right = nodeToDelete.parent = null;  
                if (nodeToDelete.color == false) {  
                    fixAfterDeletion(replacement);  
                }  
            } else if (parent == null) {  
                root = null;  
            } else {  
                if (isLeftChild) {  
                    parent.left = null;  
                } else {  
                    parent.right = null;  
                }  
  
                if (nodeToDelete.color == false) {  
                    fixAfterDeletion(parent);  
                }  
            }  
        } else {  
            Node successor = getSuccessor(nodeToDelete);  
  
            if (nodeToDelete.parent != null) {  
                if (nodeToDelete == nodeToDelete.parent.left) {  
                    nodeToDelete.parent.left = successor;  
                } else {  
                    nodeToDelete.parent.right = successor;  
                }  
            } else {  
                root = successor;  
            }  
  
            successor.parent = nodeToDelete.parent;  
            successor.left = nodeToDelete.left;  
            nodeToDelete.left.parent = successor;  
  
            if (successor != nodeToDelete.right) {  
                successor.right = nodeToDelete.right;  
                nodeToDelete.right.parent = successor;  
            }  
  
            if (nodeToDelete.color == false) {  
                fixAfterDeletion(successor);  
            }  
  
            nodeToDelete.left = nodeToDelete.right = nodeToDelete.parent = null;  
        }  
    }  
  
    private Node getSuccessor(Node node) {  
        Node successorParent = node;  
        Node successor = node.right;  
        while (successor.left != null) {  
            successorParent = successor;  
            successor = successor.left;  
        }  
  
        if (successor != node.right) {  
            successorParent.left = successor.right;  
            successor.right = node.right;  
            node.right.parent = successor;  
        }  
  
        return successor;  
    }  
  
    // 查找节点  
    public Node find(int data) {  
        return findRec(root, data);  
    }  
  
    private Node findRec(Node root, int data) {  
        if (root == null) {  
            return null;  
        }  
        if (root.data == data) {  
            return root;  
        } else if (data < root.data) {  
            return findRec(root.left, data);  
        } else {  
            return findRec(root.right, data);  
        }  
    }  
  
    // 修复红黑树属性  
    private void fixViolation(Node node) {  
        Node parent = null;  
        Node grandParent = null;  
  
        while ((node != root) && (node.color != false) && (node.parent.color == true)) {  
            parent = node.parent;  
            grandParent = parent.parent;  
  
            if (parent == grandParent.left) {  
                Node uncle = grandParent.right;  
  
                if (uncle != null && uncle.color == true) {  
                    grandParent.color = true;  
                    parent.color = false;  
                    uncle.color = false;  
                    node = grandParent;  
                } else {  
                    if (node == parent.right) {  
                        rotateLeft(parent);  
                        node = parent;  
                        parent = node.parent;  
                    }  
  
                    rotateRight(grandParent);  
                    boolean temp = parent.color;  
                    parent.color = grandParent.color;  
                    grandParent.color = temp;  
                    node = parent;  
                }  
            } else {  
                Node uncle = grandParent.left;  
  
                if ((uncle != null) && (uncle.color == true)) {  
                    grandParent.color = true;  
                    parent.color = false;  
                    uncle.color = false;  
                    node = grandParent;  
                } else {  
                    if (node == parent.left) {  
                        rotateRight(parent);  
                        node = parent;  
                        parent = node.parent;  
                    }  
  
                    rotateLeft(grandParent);  
                    boolean temp = parent.color;  
                    parent.color = grandParent.color;  
                    grandParent.color = temp;  
                    node = parent;  
                }  
            }  
        }  
  
        root.color = false;  
    }  
  
    private void rotateLeft(Node node) {  
        Node rightChild = node.right;  
        node.right = rightChild.left;  
  
        if (node.right != null) {  
            node.right.parent = node;  
        }  
  
        rightChild.parent = node.parent;  
  
        if (node.parent == null) {  
            root = rightChild;  
        } else if (node == node.parent.left) {  
            node.parent.left = rightChild;  
        } else {  
            node.parent.right = rightChild;  
        }  
  
        rightChild.left = node;  
        node.parent = rightChild;  
    }  
  
    private void rotateRight(Node node) {  
        Node leftChild = node.left;  
        node.left = leftChild.right;  
  
        if (node.left != null) {  
            node.left.parent = node;  
        }  
  
        leftChild.parent = node.parent;  
  
        if (node.parent == null) {  
            root = leftChild;  
        } else if (node == node.parent.right) {  
            node.parent.right = leftChild;  
        } else {  
            node.parent.left = leftChild;  
        }  
  
        leftChild.right = node;  
        node.parent = leftChild;  
    }  
  
    private void fixAfterDeletion(Node node) {  
        while ((node != root) && (node.

文心一言代码最后生成失败了。

3.力扣算法题

文心一言的回答:

class Solution {  
    public boolean canPartitionKSubsets(int[] nums, int k) {  
        int sum = 0;  
        for (int num : nums) {  
            sum += num;  
        }  
        if (sum % k != 0) {  
            return false;  
        }  
          
        int target = sum / k;  
        int[] subsetSums = new int[k];  
        Arrays.sort(nums); // 排序可以优化搜索过程  
        return dfs(nums, nums.length - 1, subsetSums, target);  
    }  
      
    private boolean dfs(int[] nums, int index, int[] subsetSums, int target) {  
        if (index == -1) {  
            for (int sum : subsetSums) {  
                if (sum != target) {  
                    return false;  
                }  
            }  
            return true;  
        }  
          
        int num = nums[index];  
        for (int i = 0; i < subsetSums.length; i++) {  
            if (subsetSums[i] + num <= target) {  
                subsetSums[i] += num;  
                if (dfs(nums, index - 1, subsetSums, target)) {  
                    return true;  
                }  
                subsetSums[i] -= num;  
            }  
            // 如果subsetSums[i]为0,或者num与subsetSums[i]之前的数相等,则跳过当前循环  
            // 这是因为同一个集合中的数字应该是唯一的,且我们不想重复计算相同的组合  
            if (subsetSums[i] == 0 || num == nums[index + 1]) {  
                break;  
            }  
        }  
        return false;  
    }  
}

ChatGPT的回答:

import java.util.Arrays;
​
class Solution {
    public boolean canPartitionKSubsets(int[] nums, int k) {
        int sum = 0;
        for (int num : nums) {
            sum += num;
        }
        
        // 如果不能整除,返回 false
        if (sum % k != 0) {
            return false;
        }
​
        int target = sum / k;
        Arrays.sort(nums);
        int n = nums.length;
        int[] subsetSums = new int[k];
        boolean[] visited = new boolean[n];
        
        // 从大到小进行处理
        for (int i = 0; i < n / 2; i++) {
            int temp = nums[i];
            nums[i] = nums[n - i - 1];
            nums[n - i - 1] = temp;
        }
        
        return canPartition(nums, subsetSums, visited, target, 0, k);
    }
​
    private boolean canPartition(int[] nums, int[] subsetSums, boolean[] visited, int target, int index, int k) {
        if (index == nums.length) {
            for (int i = 0; i < k; i++) {
                if (subsetSums[i] != target) {
                    return false;
                }
            }
            return true;
        }
​
        int num = nums[index];
        for (int i = 0; i < k; i++) {
            if (subsetSums[i] + num <= target) {
                subsetSums[i] += num;
                visited[index] = true;
                
                if (canPartition(nums, subsetSums, visited, target, index + 1, k)) {
                    return true;
                }
                
                subsetSums[i] -= num;
                visited[index] = false;
            }
​
            // 剪枝:如果第一个桶都不能满足条件,后面的桶也不需要尝试
            if (subsetSums[i] == 0) {
                break;
            }
        }
​
        return false;
    }
}

4.再来一道算法题

ChatGPT给出的答案:

class Solution {
    public int longestValidParentheses(String s) {
        int maxLength = 0;
        int[] dp = new int[s.length()];
​
        for (int i = 1; i < s.length(); i++) {
            if (s.charAt(i) == ')') {
                if (s.charAt(i - 1) == '(') {
                    dp[i] = (i >= 2 ? dp[i - 2] : 0) + 2;
                } else if (i - dp[i - 1] > 0 && s.charAt(i - dp[i - 1] - 1) == '(') {
                    dp[i] = dp[i - 1] + ((i - dp[i - 1] >= 2) ? dp[i - dp[i - 1] - 2] : 0) + 2;
                }
                maxLength = Math.max(maxLength, dp[i]);
            }
        }
​
        return maxLength;
    }
}

image-20240825203439819

文心一言给出的答案:

class Solution {  
    public int longestValidParentheses(String s) {  
        int maxLen = 0;  
        int[] dp = new int[s.length()];  
          
        for (int i = 1; i < s.length(); i++) {  
            if (s.charAt(i) == ')') {  
                if (s.charAt(i - 1) == '(') {  
                    dp[i] = (i >= 2 ? dp[i - 2] : 0) + 2;  
                } else if (i - dp[i - 1] > 0 && s.charAt(i - dp[i - 1] - 1) == '(') {  
                    dp[i] = dp[i - 1] + ((i - dp[i - 1]) >= 2 ? dp[i - dp[i - 1] - 2] : 0) + 2;  
                }  
                maxLen = Math.max(maxLen, dp[i]);  
            }  
        }  
          
        return maxLen;  
    }  
}

ChatGPT和文心一言给出了相同的答案。

5.中文能力

ChatGPT的回复:


尊敬的辅导员:

您好!

今天我感觉身体有些不适,可能是最近的学习压力有点大导致的。我觉得需要休息一下,让身体尽快恢复。虽然暂时不能参加今天的课程,但我会尽力在身体好转后尽快补上学习内容,不影响整体的进度。

希望您能理解并批准我的请假请求,非常感谢您的关心与支持!

祝您一切顺利!

此致

敬礼 [你的姓名] [日期]


文心一言的回复:


尊敬的辅导员老师:

您好!我是XX班的学生XXX,由于近期身体不适,感觉身体状况欠佳,可能需要休息和调整。为了不耽误课程学习,也为了避免病情加重影响其他同学,我想请假X天,从XXXX年XX月XX日至XXXX年XX月XX日,前往医院就诊并休息。在此期间,我会尽量通过自学和同学的帮助,补上落下的课程内容。

希望您能理解我的情况,并批准我的请假申请。如有需要,我可以提供医院的诊断证明。

感谢您的关心和理解!

此致 敬礼!

学生:XXX XXXX年XX月XX日


希望这段理由能帮到您,祝您早日康复!

6.识图能力

文心一言的回答:

ChatGPT的回答:

7.画图功能

但是ChatGPT可以对画完的图片进行标识修改