相关疑难解决方法(0)

更优雅的方法来检查C++数组中的重复项?

我在C++中编写此代码作为uni任务的一部分,我需要确保数组中没有重复项:

// Check for duplicate numbers in user inputted data
    int i; // Need to declare i here so that it can be accessed by the 'inner' loop that starts on line 21
    for(i = 0;i < 6; i++) { // Check each other number in the array
        for(int j = i; j < 6; j++) { // Check the rest of the numbers
            if(j != i) { // Makes sure don't check number against itself
                if(userNumbers[i] == userNumbers[j]) { …
Run Code Online (Sandbox Code Playgroud)

c++ arrays duplicates

16
推荐指数
6
解决办法
7万
查看次数

标签 统计

arrays ×1

c++ ×1

duplicates ×1