1、C开发笔试题0813C开发笔试题-20130813、不定项选择题1、以下变量的定义,正确的是( CD)A.int 3man; C. int i, *pi;B.int 3manshoes; D. short int si;注:标示符规则:C语言规定必须以字母或下划线_(Underscore)开头,后面可以跟若干个字母、数字、下划线,但不能有其它字符。避免使用下划线开头 2、对于如下的定义,说法正确的有( A )int * pb,pc;A、pb是一个指向整数的指针,pc是一个整数 C、这个定义是错的B、pb和pc都是指向整数的指针 D、这个定义是对的,但在编译时会出现告警3、以下代码的运行结果是(
2、 BC )代码:unsigned int uiA;uiA = (0AB & CD) (0EF | AB);代码:unsigned int uiBuiB =AA | (BB 8) |(CC16) | (DD 3) 3 )=uiNum )5.关于以下代码,描述正确的有( )代码: const char * pcStr=”abcdefg”;char *pcStr=”abcdefg”代码:void string_sizeof(char szStr110) char szStr210=”12345”; static int iCount=1; iCount=iCount+iInputNum; Print
3、(“n iCount =%d”,icount+iInputNum);for(i=1;i3;i+) Fun(i);A.iCount =3 B.iCount =4 C.iCount =6 D.iCount =512.关于以下代码,输出结果是( )Void Fun( ) Int i; Int x33=1,2,3, 4,5,6, 7,8,9; Int *p; P=& x 11; For(i=0;ipatNext;pstD-pstNext=pstB;pstA-pstNext=pstD;free(pstB);B.pstA-pstNext=pstD;pstD-pstNext=pstA-pstNext-pst
4、Next;free(pstB);CpstA-pstNext-pstNext-pstpre=pstD;pstD-pstNext=pstA-pstNext-pstNext;pstD-pstpre=pstB-pstpre;pstA-pstNext=pstB-pstNext-pstpre;free(pstB);D.pstD-pstNext=pstB-pstNext;pstD-pstNext-pstpre=pstD;pstD-pstpre=pstA;pstA-pstNext=pstD;free(pstB);1、数据的节点定义如下面的tagData所列,该数据节点有两个索引值,分别是index1和inde
5、x2,请编写程序,有如下要求:1)据上下文,由于需要分别以index1和index2索引查找,请建立两个单向链表,分别以index1和index2,索引值唯一,且均为从小到大2)提供增加节点的函数和删除节点的操作,请注意增加和删除节点的操作均会影响这两个链表。3)删除操作数据是依据index2删除的/*节点数据*/typedef struct tagData int index1; int index2; int iData; struct tagData *pstNext1; struct tagData *pstNext2;NODE_S;/*Description:链表初始化*/void
6、init();/*Description:加入节点*/void add(int index1,int index2,int iData);/*Description:删除节点*/Void delete(int index2);Code:#includeusing namespace std;struct TagData int nIndex1; int nIndex2; int iData; struct TagData *pstNext1; struct TagData *pstNext2;NODE_S;/Initvoid InitTagData() NODE_S.iData=0; NODE
7、_S.nIndex1=0; NODE_S.nIndex2=0; NODE_S.pstNext1=NODE_S.pstNext2 = NULL;void AddTagData(int nIndex1,int nIndex2,int iData) struct TagData *psttemp =new struct TagData; psttemp-iData = iData; psttemp-nIndex1 = nIndex1; psttemp-nIndex2 = nIndex2; psttemp-pstNext1 = NULL; psttemp-pstNext2 = NULL; struct
8、 TagData *p=&NODE_S; while(p-pstNext1)&(p-pstNext1-nIndex1)pstNext1; psttemp-pstNext1 = p-pstNext1; p-pstNext1 = psttemp; p= &NODE_S; while(p-pstNext2)&(p-pstNext2-nIndex2)pstNext2; psttemp-pstNext2 = p-pstNext2; p-pstNext2 = psttemp;void DeleteTagData(int nIndex2) struct TagData *p=&NODE_S; while(p
9、-pstNext2&(p-pstNext2-nIndex2)!=nIndex2) p= p-pstNext2; if (!p-pstNext2) cout pstNext2; p-pstNext2=p-pstNext2-pstNext2; p=&NODE_S; while(p-pstNext1&(p-pstNext1-nIndex2)!=nIndex2) p= p-pstNext1; p-pstNext1 = p-pstNext1-pstNext1; delete(temp);void show() struct TagData *p = NODE_S.pstNext1; while(p) c
10、out iData pstNext1; cout endl; p= NODE_S.pstNext2; while(p) cout iData pstNext2; cout endl;int main() AddTagData(2,5,7); AddTagData(3,2,16); AddTagData(4,3,15); DeleteTagData(2); show(); return 0;2、请写冒泡排序算法,a指向数组第一个元素,n为数组长度void bubble_sort(int *a, int n) int I, j, key; for(i = 0;i i; j-) if(aj aj +
11、 1) key = aj; aj = aj+1; aj+1 = key; int main(void) int i = 0; int a = 8,4,9,2,7,12; bubble_sort(a, 6); for(i = 0; I 6; +i) printf(“%d ”, ai); return 0;3、五个学生,三门成绩,输入学号,姓名,三门课的成绩。算出三门课的平均值,连同原始数据一起保存到“stduo”的文件中。#include #include #define N i5 struct Student char m_id9; char m_name10; int m_math, m_e
12、nglish, m_chinese, m_average; studentN;int main() int i = 0; FILE *fp; for(i = 0; i N; +i) printf(输入学生ID:); scanf(%s, studenti.m_id); printf(输入学生姓名:); scanf(%s, studenti.m_name); printf(输入数学成绩:); scanf(%d, &studenti.m_math); printf(输入学生英语成绩:); scanf(%d, &studenti.m_english); printf(输入学生语文成绩:); scanf
13、(%d, &studenti.m_chinese); studenti.m_average = (studenti.m_math +studenti.m_english +studenti.m_chinese)/3; if(fp = fopen(stduo, w) = NULL) perror(文件打开失败!); exit(0); fwrite(student, sizeof(struct Student), N, fp); fclose(fp); return 0;4、同一花色的扑克牌13张。将第一张放入最后,抽取最上面的一张,在将最上面的一张放入最后,以此类推。最后结果是A23456789
14、10jQk求原始的牌的顺序。#include#include#define num 13/总的数据个数#define next 2/每隔几个出圈int joseph(int m,int k,int i) if(i=1) return (m+k-1)%m; else return (joseph(m-1,k,i-1)+k)%m; int main() int i; int anum; int bnum; printf(序列出圈数据为:); for(i=1;i=num;i+) ai-1=joseph(num,next,i)+1; printf(%d ,ai-1); printf(n牌的原始序列为:
15、); for(i=0;inum;i+) bai-1=i+1; for(i=0;ib-c-d-e是一个双向链表,链表结构体如下typedef struct NodeTest int data; struct NodeTest *next; struct NodeTest *pre;NodeTest_t;实现接口:NodeTest_t *reset(NodeTest_t *node);功能:例如:传入参数为此链表的c成员,则通过该接口把链表重置为c-d-e-a-b,返回新的链表头2.算税后余额:01500 %515004500 %1045008000 15%800010000 20%10000以上
16、 30%假设一个人工资为9000,则他应缴纳税那部分金额为 9000-3500 = 5500则他应缴纳的税收为 1500*5%+3000*10% +(5500-4500)*15% = 525则缴纳税后他应发工资 8000 - 525 = 7475写接口计算税后余额double CalTax(double money);传入的参数为你扣完社保后的工资#include stdio.hint main() double Wage, Tax = 0, AfterTaxWages;printf(Please put in the wage:n);while (1) scanf(%lf, &Wage);i
17、f (Wage 0 & Wage 1500 & Wage 2500 & Wage 3500 & Wage 5000 & Wage = 10000) Tax = (Wage - 5000) * 0.30;AfterTaxWages = Wage - Tax; else Tax = (Wage - 10000) * 0.40;AfterTaxWages = Wage - Tax;printf(The Tax = %lfn, Tax);printf(The after-tax wage = %lfn, AfterTaxWages);printf(nn*nn);printf(Put in anothe
18、r wage:n);return 0;程序题1.输入一字符串,统计字母,数字与其他符号的数量#includeint main(void) /输入一行字符,分别统计出其中英文字母、空格、数字和其他字符的个数。char ch; int char_num=0,kongge_num=0,int_num=0,other_num=0; while(ch=getchar()!=n)/回车键结束输入,并且回车符不计入 if(ch=a&ch=z|ch=a) char_num+; else if(ch= ) kongge_num+; else if(ch=0&ch=9) int_num+; else other_
19、num+; printf(字母= %d,空格= %d,数字= %d,其它= %dn,char_num,kongge_num,int_num,other_num); return 0;3.数字转换成字符 如数字465 转换成字符“465”(题的意思是这样,原题描述没记下来)解析:整数转换成字符串,可以采用加0,在逆序的方法,整数加0就会隐性转换成char类型的数#include Int main()Int num = 12345, j = 0, i = 0;Char temp7, str7;While(num)Tempi = num % 10 + 0;I+;Num /= 10;Tempi = 0
20、;Printf(“temp = %sn”, temp);I = i - 1;Printf(“temp = %dn”, i );/逆序While(i = 0)Strj = tempi;J+;I-;Strj = 0;Printf(“string = %sn”, str);Return 0;1、给一个结构体(15分)Struct NODE_Sint data;NODE_S *next;NODE_S *preptr;给一个头指针指向该结构体的节点的链表,写一函数判断该链表是否是双向循环链表。Typdef struct NODE_S NODE;int IsDuLinkList( NODE* L)If(L
21、 & L-next = L-preptr = L)printf(“链表是双向循环链表n”);Return 1;ElsePrintf(“不是双向循环链表n”);Return 0;2、给一个字符串,写一个函数返回该字符串的最长回文子串的长度,无回文子串则返回0。(20分) si = #; pi = 0; for (i = 0; stri != 0; +i) s(i + 1) 1 = stri; s(i + 1) i) pi = min(mx - i, p(id mx) mx = i + pi; id = i; if (pi - 1 ans) ans = pi - 1; /更新最长回文子串的长度 i
22、nt main() int Case = 0; while (scanf(%s, str) != EOF) if (strcmp(str, END) = 0) break; Manacher(); printf(Case %d: %dn, +Case, ans); return 0;6、有关霍夫曼树和平衡树的选择题(定义什么的去看看,有个选项说霍夫曼树可应用于编码)7、有一题关于获取mac地址的函数(题目给出一个函数的实现代码),考的是字符串的东西,还有sprintf函数(下面是函数中运用sprintf函数的代码: sprintf(mac,%02X-%02X-%02X-%02X-%02X-%0
23、2X, Adapter.adapt.adapter_address0, Adapter.adapt.adapter_address1, Adapter.adapt.adapter_address2, Adapter.adapt.adapter_address3, Adapter.adapt.adapter_address4, Adapter.adapt.adapter_address5);)QString GetLocalMac()int sock_mac;struct ifreq ifr_mac;char mac_addr30;sock_mac = socket( AF_INET, SOCK_STREAM, 0 );if( sock_mac = -1
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1