int ii, maxnum;
for(ii=1; ii<=num-1; ii++) {
if(count[ii]>max) { // the part where I get C2872 Ambiguous Symbol error
max = count[ii]; // the part where I get C2872 Ambiguous Symbol error
maxnum = ii;
}
}
Run Code Online (Sandbox Code Playgroud)
我从来没有得到过这个错误,这令人沮丧.
例如,
int num[] = {1, 5, 3, 12, 5, 1, 4};
int len = 7;
int count = 0;
Run Code Online (Sandbox Code Playgroud)
(假设数组中的相同元素不超过2个)
那么我会做
for(int i=0; i<len-1; i++) {
for(int j=i+1; j<len; j++) {
if(num[i] == num[j]) {
count++;
}
}
}
Run Code Online (Sandbox Code Playgroud)
那么计数将为2。
但是该算法导致了O(N ^ 2)的效率。
有没有更有效的方法?
先感谢您!
可能重复:
如何在C++中使用数组?
我不知道如何推送一个char数组.
例如,如果我在char数组中有"HI.MY.NAME.IS",
我想在中间放一个字符并将字符向右推.
所以它会像"HI.MY.SLAME.IS"之类的东西.
任何可能的解决方