#3924. [GESP202312 七级 C++] 第 6 题

[GESP202312 七级 C++] 第 6 题

哈希表长 31,按照下面的程序依次输入 4 17 28 30 4,则最后的 4 存入哪个位置?( )

#include <iostream>
#include <string>
#include <cmath>
#include <vector>
using namespace std;

const int N=31;
int htab[N],flag[N];
int main()
{
    int n,x,i,j,k;

    cin >> n;
    for(i=0; i<n; i++){
        cin >> x;
        k=x%13;
        while(flag[k]) k = (k+1)%13;
        htab[k]=x;
        flag[k]=1;
    }

    for(i=0; i<N; i++)
        cout << htab[i] << " ";

    cout << endl;
    return 0;
}

{{ select(1) }}

  • 3
  • 4
  • 5
  • 6