關於我自己

2018年10月14日 星期日

[面試] 群聯 Linux kernel 2018/10/9


群聯

筆試給了試題和兩張白紙,第一題就是寫出keygen,
以前也有寫過JS版本的
分析:
面試主要是Linux相關所以用C/C++撰寫
C的版本在於只有兩張紙還有大約10題,必定不適合寫個Link list...
於是直接alloc裝Key...




1. 寫一個keygen 0-F 6個字gen出不重複的key

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>
#define ARRY_SIZE(A) (sizeof(A)/sizeof(A[0]))
char allowChar [] =
{
    '0','1','2','3','4','6','7','8','9','A','B','C','D','E','F'
};


char *keyList;



char getChar(){
    return allowChar[rand()%ARRY_SIZE(allowChar)];
}

bool inList(  char * keyListPtr , int currentListLength , int keySize ,char *tmpKey )
{
    char *keyPtr;

    int i;
    for(i  = 0 ; i < currentListLength; i ++ )
    {
        keyPtr = keyListPtr+ i*keySize;
        if( strcmp(keyPtr ,tmpKey ) == 0)
            return true;

    }
return false;
}
char *genKey( char *keyListPtr ,int keyNumber,int Length){
    int i,j,totalBufferSize,keySize;
    keySize =  Length +1 ;
    totalBufferSize = keyNumber*keySize;
    char *tmpKey = (char *)malloc(keySize);
    keyListPtr = (char * ) malloc( totalBufferSize  );
    memset(keyListPtr , 0 , totalBufferSize);

    j = 0;
    while( j < keyNumber )
    {
        memset(tmpKey, 0 ,keySize);
        for( i = 0 ; i < Length ; i++ )
            *(tmpKey+i) = getChar();
        if( !inList(  keyListPtr , j , keySize ,tmpKey )  )
        {
            memcpy( keyListPtr + j*keySize , tmpKey , keySize);
            j++;
        }
    }
    free(tmpKey);
    printf("Gen Done!\n");
    return keyListPtr;
}


void display(  char * keyListPtr , int currentListLength , int keySize ){
    char *keyPtr;

    int i;

    for(i  = 0 ; i < currentListLength; i ++ )
    {
        keyPtr = keyListPtr + i*keySize;
        printf("key[%4d] : %s\n",i,keyPtr);

    }
return ;
}

int main()
{
    int keyNumber = 30;
    int keyLength = 6;
    char * keyList;


    keyList = genKey( keyList , keyNumber , keyLength );
    display(keyList ,keyNumber  , keyLength + 1  );

    free(keyList);

    return 0;
}



find gcc in linux kernel

find /usr/ -type f -name "gcc"

2018年6月16日 星期六

Aeron Chair 全功能版該不該買?


1. 是否能承擔腰痛造成的困擾?

2. 是否能承擔腰痛到無不睡著的代價?

4. 目前家具搬家費用預估1萬NT 是否能承擔?
Y

5. 2018/06/17 陸製全功能版 特價25999 造成負擔很大嗎?
閒錢,只是嫌貴

6. 是否要每次因為特價浪費一整天看網頁?


7. 買了之後發現不好用是否能承擔二手轉賣的價差?
YES