白天是个程序员,晚上就是个有抱负的演员,这是就是我,我住在天朝的陪都。

某大数据工程师笔试试题

题目见附件

试题一,没任何难度,估计是给笔试者的福利
试题二,起初笔者对题目的描述理解有偏差(题目中对LCOUNT理解出错),导致思维进入了死胡同(太久不练手的后遗症)。
答案为:

  1. K = 2
  2. LCOUNT = 0; B = N[K - 1]
  3. B++
  4. B = 1
  5. LCOUNT < L
  6. P[B] = 0
#include <stdio.h>   
int main(int argc, char *argv[])
{
    int M = 100;
    int L = 30;

    int LCOUNT, K;
    int P[101];
    int N[101];

    for(int i = 1; i <= 100; i++){
        P[i] = 1;
        N[i] = -1;
    }

    N[1] = 1;
    P[1] = 0;

    int B = 1;
__lable1:
    K = 2;
    while( K<= 100){
__lable2:
        LCOUNT = 0;
        B =  N[K - 1];
        do {
__lable3:
            B++;
            if(B > 100){
__lable4:
                B = 1;
            }
        } while(P[B] == 0);

        LCOUNT++;
__lable5:
        if(LCOUNT < L){
            goto __lable3;
        }
        printf("!!! K=%d B=%d LCOUNT=%d\n", K, B, LCOUNT);
        N[K] = B;
__lable6:
        P[B] = 0;
        K++;
    }

    //    for(int i = 1; i <= 100; i++){
    //        printf("%d ", N[i]);
    //    }
    //    printf("\n");


    printf("N[%d]=%d\n", M, N[M]);
    return 0;
}

试题三,就是一个矩阵填充,不用心一推敲就可以得到答案。
答案为:

  1. L < 2 * N
  2. 2 * N - L
  3. L + 1 - N
  4. J = N
  5. I = I + 1
  6. J = J - 1
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main(int argc, char *argv[])
{
    int K = 0, L = 1;
    
    //input params
    int N = 5;
    int M;
    int **A = NULL;
    
    int _N = N + 1;
    A = (int **)malloc(_N * sizeof(int *));
    if(!A){
        return -1;
    }
    
    A[0] = (int *)malloc(_N * _N * sizeof(int));
    if(!A[0]){
        free(A);
        return -2;
    }
    
    for(int i = 1; i < _N; i++){
        A[i] = A[i-1] + N;
    }
    
    for(int i = 1; i < _N; i++){
        for(int j = 1; j < _N; j++){
         A[i][j] = -1;
        }
    }

    while(L < 2 * N){
        int I, J;
        if(L <= N){
            M = L;
            I = 1;
            J = L;
        } else {
            M = 2 * N - L;
            I = L + 1 - N;
            J = N;
        }

        while(M > 0){
            K++;
            
            if(L % 2 == 0){
                // printf("I=%d, J=%d, K=%d\n", I, J, K);
                A[I][J] = K;                
            } else {
                // printf("J=%d, I=%d, K=%d\n", J, I, K);                
                A[J][I]  = K;
            }
            I = I + 1;
            J = J - 1;
                    
            M--;
        }
        L++;        
    }
    
    
    printf("\n");    
    for(int i = 1; i < _N; i++){
        for(int j = 1; j < _N; j++){
            printf("%4d ", A[i][j]);
        }
        printf("\n");        
    }
    
    
    free(A[0]);
    free(A);
    return 0;
}

试题.pdf

添加新评论

咻~