没有合适的资源?快使用搜索试试~ 我知道了~
嵌入式软件工程师笔试题.pdf
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 31 浏览量
2023-10-16
16:19:12
上传
评论
收藏 407KB PDF 举报
温馨提示
试读
35页
嵌入式软件工程师笔试题.pdf
资源推荐
资源详情
资源评论
1、将一个字符串逆序
2、将一个链表逆序
3、计算一个字节里( byte )里面有多少 bit 被置 1
4、搜索给定的字节 (byte)
5、在一个字符串中找到可能的最长的子字符串
6、字符串转换为整数
7、整数转换为字符串
/** 题目:将一个字符串逆序
* 完成时间: 2006.9.30 深圳极讯网吧
* 版权归刘志强所有
* 描述:写本程序的目的是希望练一下手,希望下午去面试能成功,不希望国庆节之后再去找工作拉!
*/
#include <iostream>
using namespace std;
//#define NULL ((void *)0)
char * mystrrev(char * const dest,const char * const src)
{
if (dest==NULL && src==NULL)
return NULL;
char *addr = dest;
int val_len = strlen(src);
dest[val_len] = ' ';
int i;
for (i=0; i<val_len; i++)
{
*(dest+i) = *(src+val_len-i-1);
}
return addr;
}
main()
{
char *str="asdfa";
char *str1=NULL;
str1 = (char *)malloc(20);
if (str1 == NULL)
cout<<"malloc failed";
cout<<mystrrev(str1,str);
free(str1);
str1=NULL;// 杜绝野指针
}
p=head;
q=p->next;
while(q!=NULL)
{
temp=q->next;
q->next=p;
p=q;
q=temp;
}
这样增加个辅助的指针就行乐。
ok 通过编译的代码:
#include <stdio.h>
#include <ctype.h>
#include <stdlib.h>
typedef struct List{
int data;
struct List *next;
}List;
List *list_create(void)
{
struct List *head,*tail,*p;
int e;
head=(List *)malloc(sizeof(List));
tail=head;
printf("\nList Create,input numbers(end of 0):");
scanf("%d",&e);
while(e){
p=(List *)malloc(sizeof(List));
p->data=e;
tail->next=p;
tail=p;
scanf("%d",&e);}
tail->next=NULL;
return head;
}
List *list_reverse(List *head)
{
List *p,*q,*r;
p=head;
q=p->next;
while(q!=NULL)
{
r=q->next;
q->next=p;
p=q;
q=r;
}
head->next=NULL;
head=p;
return head;
}
void main(void)
{
struct List *head,*p;
int d;
head=list_create();
printf("\n");
for(p=head->next;p;p=p->next)
printf("--%d--",p->data);
head=list_reverse(head);
printf("\n");
for(p=head;p->next;p=p->next)
printf("--%d--",p->data);
}
编写函数数 N个 BYTE的数据中有多少位是 1。
解:此题按步骤解:先定位到某一个 BYTE数据;再计算其中有多少个 1。叠加得解。
#incluede<iostream>
#define N 10
// 定义 BYTE类型别名
#ifndef BYTE
typedef unsigned char BYTE;
#endif
int comb(BYTE b[],int n)
{
int count=0;
int bi,bj;
BYTE cc=1,tt;
// 历遍到第 bi 个 BYTE数据
for(bi=0;bi<n;bi++)
{
// 计算该 BYTE的 8 个 bit 中有多少个 1
tt=b[bi];
for(bj=0;bj<8;bj++)
{
// 与 1 相与或模 2 结果是否是 1?测试当前 bit 是否为 1
//if(tt%2==1)
if((tt&cc)==1)
{
count++;
}
// 右移一位或除以 2,效果相同
//tt=tt>>1;
tt=tt/2;
}
}
return count;
}
// 测试
int main()
{
BYTE b[10]={3,3,3,11,1,1,1,1,1,1};
cout<<comb(b,N)<<endl;
return 0;
}
1。编写一个 C 函数,该函数在一个字符串中找到可能的最长的子字符串,且该字符串是由同一字符组成
的。
char * search(char *cpSource, char ch)
{
char *cpTemp=NULL, *cpDest=NULL;
int iTemp, iCount=0;
while(*cpSource)
{
if(*cpSource == ch)
{
iTemp = 0;
cpTemp = cpSource;
while(*cpSource == ch)
++iTemp, ++cpSource;
if(iTemp > iCount)
iCount = iTemp, cpDest = cpTemp;
if(!*cpSource)
break;
}
++cpSource;
}
return cpDest;
}
#include <stdio.h>
#include <string.h>
//
// 自定义函数 MyAtoI
// 实现整数字符串转换为证书输出
// 程序不检查字符串的正确性 , 请用户在调用前检查
//
int MyAtoI(char str[])
{
int i;
int weight = 1; // 权重
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];
剩余34页未读,继续阅读
资源评论
2201_75761617
- 粉丝: 21
- 资源: 7339
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功