小编use*_*949的帖子

错误:预期','或';' 在'for'之前

我无法想象发生了什么.我收到关于我的第二个for循环的错误,这是循环遍历地图的错误.我想,这个简单的程序会找到数组中最常见的元素.

#include <iostream>
#include <map>

int mode(int* arr, int sz) { 
    std::map<int,int> M;
    for (int i = 0; i < sz; i++) {
       if (M.count(arr[i]) == 0) { 
           M[arr[i]] = 1;
       } else { 
           M[arr[i]]++;
       }
    }
    int largest = arr[0]
    for (std::map<int,int>::iterator it = M.begin(); it != M.end(); it++) { 
       if (it->first > largest) {
           largest = it->first;
       }
    }
    return largest;
}

int main() {

  int myArray[] = {1, 2, 5, 0, 10, 4, -4, 10, 69, 10, …
Run Code Online (Sandbox Code Playgroud)

c++

-4
推荐指数
1
解决办法
2992
查看次数

标签 统计

c++ ×1