Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/154.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 什么';s在c+中使用int hash[a]={0}+;,它是如何工作的? for(int i=0;i>b; arr[i]=b; } int散列[100]={0}; int i=0; 而(i_C++_C++17 - Fatal编程技术网

C++ 什么';s在c+中使用int hash[a]={0}+;,它是如何工作的? for(int i=0;i>b; arr[i]=b; } int散列[100]={0}; int i=0; 而(i

C++ 什么';s在c+中使用int hash[a]={0}+;,它是如何工作的? for(int i=0;i>b; arr[i]=b; } int散列[100]={0}; int i=0; 而(i,c++,c++17,C++,C++17,在这种情况下,数字0实际上是无用的。它除了提醒程序员它应该做什么之外,什么都不做 for(int i=0; i< a; i++){ cin>>b; arr[i]=b; } int hash[100]={0}; int i = 0; while (i<a) { hash[arr[i]-1]++;

在这种情况下,数字
0
实际上是无用的。它除了提醒程序员它应该做什么之外,什么都不做

for(int i=0; i< a; i++){
            cin>>b;
            arr[i]=b;
        }
        int hash[100]={0}; 
        int i = 0; 
        while (i<a) 
        { 
            hash[arr[i]-1]++; 
            i++; 
        }
        int arr1[a];
        for (int i=0; i<a; i++){
            arr1[i]=hash[i]; 
        }

int散列[100]={0};
创建一个包含100个整数的数组,并将其全部设置为零。这就是你要问的问题吗?如果不是,请说明你不明白的地方。如果你不懂算法,那么试着用纸和笔浏览一个小例子,你很快就会看到它是如何工作的。@john我明白了,但你能解释一下它是如何计算发生的吗rence.@bharandaran事件在此处计数:
hash[arr[i]-1]如果你问了一个新问题,你可以考虑把一个新的问题扩展到A。谢谢大家,我用笔和纸试过了,现在我已经理解了。你能解释一下吗?gorithm,我是说它是如何计算发生率的。@Bharandaran对不起,我一直在回答你问的问题。对不起,我现在拿到了,我现在用笔和纸试过了。谢谢你的补充:
int e[100]={};
@acocagua那么我们还需要提到
int f[100]({})
和一个里面有0的。但在这一点上,它只是变得一团糟。
int a[100]; // creates an array, but leaves the memory uninitiated, you do not know what will be there
int b[100] {}; // creates an array and fills the memory with default values, in this case values are 0
int c[100] {0}; // creates an array, fills the first one with 0 and the rest with default values, but default values are also 0
int d[100] = {0}; // equals sign in this case is there for historical reasons, it is not an assignment operator