由买买提看人间百态

topics

全部话题 - 话题: anumnotinarray
(共0页)
B*****t
发帖数: 335
1
不解释了, 给你个code参考一下就明白了
#include
using namespace std;
int main() {
const int ANumNotInArray = 0x7fffffff;
class Node {
public:
int x, cnt;
}d[3];
int m[] = {3, 2, 6, 3, 2, 1, 6, 3, 6, 2, 7};
int n, i, j;
n = sizeof(m)/sizeof(int);
bool found = false;
for(i=0; i<3; i++) {
d[i].x = ANumNotInArray;
d[i].cnt = 0;
}
for(i=0; i for(j=0; j<3; j++) {
if(m[i]==d[j].x) {
d[j].cnt++; f
B*****t
发帖数: 335
2
又改了一下,你看看还有没有bug
#include
using namespace std;
int main() {
const int ANumNotInArray = 0x7fffffff;
class Node {
public:
int x, cnt;
}d[3];
int m[] = {3,3,3,7,2,2,6,1,6,2,6};
int n, i, j, ix;
n = sizeof(m)/sizeof(int);
bool found = false;
for(i=0; i<3; i++) {
d[i].x = ANumNotInArray;
d[i].cnt = 0;
}
for(i=0; i for(j=0; j<3; j++) {
if(m[i]==d[j].x) {
d[j].cnt++; found = true
(共0页)