- 相關(guān)推薦
嵌入式軟件工程師經(jīng)典筆試題
為幫助大家鞏固嵌入式工程是基礎(chǔ)知識,yjbys小編為大家整理最新嵌入式工程師考試題如下:
1、將一個鏈表逆序
LinkList *reverse(LinkList *head)
{
LinkList *p1,*p2 = NULL,*p3 = NULL;
if(head == NULL || head->next == NULL)
return head;
p1 = head->next;
while(p1!=NULL)
{
p3 = p1->next;
p1->next = p2;
p2 = p1;
p1 = p3;
}
head->next = p2;
// head = p2;
return head;
}
2、計算一個字節(jié)里(byte)里面有多少bit被置1
#include
int comb(const int c)
{
int count = 0;
int i = 0;
int cc = c;
while(i++<8)
{
if((cc&1)==1)
{
count++;
}
cc = cc>>1;
}
return count;
}
int main()
{
const int c = 0xcf;
printf("%d\n",comb(c));
return 1;
}
3、在一個字符串中找到可能的最長的子字符串
#include
#include
#include
char *commanstring(char shortstring[],char longstring[])
{
int i,j;
char *substring = malloc(256);
if(strstr(longstring,shortstring)!=NULL)
return shortstring;
for(i=strlen(shortstring)-1;i>0;i--)
{
for(j=0;j<=strlen(shortstring)-i;j++)
{
memcpy(substring,&shortstring[j],i);
substring[i]='\0';
if(strstr(longstring,substring)!=NULL)
return substring;
}
}
return NULL;
}
void main(void)
{
char *str1 = "aocdfe";
char *str2 = "pmcdfa";
char *comman = NULL;
if(strlen(str1)>strlen(str2))
comman= commanstring(str2,str1);
else
comman = commanstring(str1,str2);
printf("the longest comman string is:%s\n",comman);
}
4、字符串轉(zhuǎn)換為整數(shù)
#include
#include
void reverse(char s[])
{ //字符串反轉(zhuǎn)
int c, i=0, j;
for(j=strlen(s)-1;i
{ c=s[i];
s[i]=s[j];
s[j]=c;
i++;
}
}
void IntegerToString(char s[],int n)
{ int i=0,sign;
if((sign=n)<0)//如果是負數(shù),先轉(zhuǎn)成正數(shù)
n=-n;
do //從個位開始變成字符,直到最高位,最后應(yīng)該反轉(zhuǎn)
{ s[i++]=n%10+'0';
}while((n=n/10)>0);
//如果是負數(shù),補上負號
if(sign<0)
s[i++]='-';
s[i]='\0';//字符串結(jié)束
reverse(s);
}
void main()
{ int m;
char c[100];
m =215;
IntegerToString(c,m);
printf("integer = %d string = %s\n", m, c);
}
5、整數(shù)轉(zhuǎn)換為字符串
#include
#include
int Atoi(char str[])
{
int i;
int weight = 1; // 權(quán)重
int rtn = 0; // 用作返回
for(i = strlen(str) - 1; i >= 0; i--)
{
rtn += (str[i] - '0')* weight; //
weight *= 10; // 增重
}
return rtn;
}
void main()
{
char str[32];
printf("Input a string :");
gets(str);
printf("%d\n", Atoi(str));
}
6、將一個字符串逆序
#include
#include
char *strconv(char *p)
{
int length = strlen(p);
char *ptr = p;
char *ptr_1 = p + length -1;
while(ptr < ptr_1)
{
char c = *ptr;
*ptr = *ptr_1;
*ptr_1 = c;
++ptr;
--ptr_1;
}
return p;
}
int main()
{
char str[]="abcdef1234";
char *p;
p = strconv(str);
printf("%s",p);
return 1;
}
【嵌入式軟件工程師經(jīng)典筆試題】相關(guān)文章:
嵌入式軟件工程師面試題06-23
2017嵌入式軟件工程師筆試題及答案02-28
初級嵌入式軟件工程師認證考試試題03-31
深圳MTK公司嵌入式軟件工程師筆試真題02-28
嵌入式助理工程師認證考試題庫01-23
2016最新嵌入式筆試題及答案01-23
嵌入式助理工程師認證考試題庫及答案01-23