嵌入式软件工程师笔试题

2009年04月11日 10:25    发布者:老郭
1、将一个字符串逆序
2、将一个链表逆序
3、计算一个字节里(byte)里面有多少bit被置1
4、搜索给定的字节(byte)
5、在一个字符串中找到可能的最长的子字符串
6、字符串转换为整数
7、整数转换为字符串


1、char *strconv(char *p)

{

    int i,length;

    char temp;

    length = strlen(p);

    for(i = 0;i < length/2;i++)

    {

        temp = *(p + i);

        *(p + i) = *(p + length - 1 - i);

        *(p +length - 1 - i) = temp;

    }

    return p;

}



int main()

{

    char src;

    char *p;

    scanf("%s",src);

    p = strconv(src);

    printf("%s\n",p);

    return 0;

}


3、int cal(int data) //calculation the number of bit in one byte

{

    int a;

    int count = 0;

    a = data % 100;

    while (a != 0)

    {

        count += a % 2;

        a /= 2;

    }

    return count;

}



int main()

{

    int d,count;

    scanf("%d",&d);

    count = cal(d);

    printf("%d of one\n",count);

    return 0;

}


4、#include

#include



void findmax(char *p)

{

    int j = 0,max = 0;

    int count = 0;

    char record;

    char recordmax;



    for(int i = 0;;i++)

    {

        

        if((*(p + i) == ' ') || (*(p + i) == '\0'))

        {        

            if(count > max)

            {

                max = count;

                record = '\0';

                strcpy(recordmax,record);            

            }

            count = 0;

            j = 0;

        }

        else

        {

            record = *(p + i);

            count ++;

            j ++;

        }

        if(*(p + i) == '\0')

            break;

    }

    printf("%s\n",recordmax);

}

            



        

int main()

{

    char str[]="zeng weidsfdsaf langd hah";

    printf("%s\n",str);

    findmax(str);

    return 0;

}