免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块
查看: 1547 | 回复: 1
打印 上一主题 下一主题

一个招聘试题,想找初程工作的来试试能力。 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2003-08-16 15:06 |只看该作者 |倒序浏览
下面是偶求职是得到的试题。我因代码不规范没能面试。


     C语言测试题

总体说明:
1、 以往我们在招聘过程中,总是收到大量的简历,还要花费很多时间进行面试,但是效果并不是很好。采用测试的方法,可以提前鉴别求职人员是否真正具有我们所需要的工作能力。
2、 本公司主要从事银行方面的应用软件开发,C语言是必备的开发工具,所以本测试题必须以C或C++语言完成,具体使用什么工具没有限制,对于刚毕业的学生,采用Tubro C也可以。
3、 下面两道题目是银行业务软件中非常普遍的应用,对于从事过这方面程序开发的人来说是非常容易的。如果你以前没有从事过这方面的工作,但是对C语言熟悉,完成这些题目也应该问题不大。



一、 基本库函数的使用及简单的算法

一个字符串,其组成规律如下:
1、 由若干个域(域的数目不定)组成。
2、 每个域有三部分构成:域代码(3 bytes)、域长度(3 bytes),域内容(长度不定,具体长度等于前面的域长度)。

例如,下面的字符串
123003abc456010123456789005hello
实际上由三个域组成:
第一个域:123003abc,表示域代码为123,域的长度为3 bytes,域的内容为abc
第二个域:4560101234567890,表示域代码为456,域的长度为10 bytes,域的内容为1234567890
第三个域:789005hello,表示域代码为789,域长度为5,域内容为hello

要求:
1、 写一个函数,能够从这样的字符串中取得指定的域内容及长度,函数规范如下:
int iGetItem(char *szSrc, char *szItemCode, char *szItemValue, int *piItemLen)

参数定义:
char *szSrc:字符串的首地址
char *szItemCode:需要寻找的域的代码字符串首地址
char *szItemValue:域内容存放的首地址
int *piItemLen:指向一个int型变量的指针,找到相应的域后,将该指针指向的变量赋值为域的长度。
2、 编写一个main函数,调用上面的iGetItem函数,测试其效果。
3、 将上述两个函数放在test1.c 或 test1.cpp 文件中,编译成可执行文件,文件名为test1.exe。
4、 可以在Windows的命令行环境下执行test.exe,带两个参数,第一个是字符串,第二个域代码,执行后显示出域的内容和长度,例如:
输入 C:\test1.exe 123003abc456010123456789005hello 789
输出 C:\Item[789],value=[hello],length=5 或 c:\no such item.


二、 记录运行日志

要求:
1、 在第一题的基础上,添加一个记录运行日志的函数。
2、 日志文件名为yyyymmdd.log,文本文件,该文件存放在可执行文件所在的目录下。
3、 文件名中的yyyymmdd表示年、月、日,取运行时的系统日期,形成文件名。
日志中记录的数据就是运行时的两个输入参数。要求这些参数分别以ASCII码及字符串形式记录

论坛徽章:
0
2 [报告]
发表于 2003-08-16 15:06 |只看该作者

一个招聘试题,想找初程工作的来试试能力。

下面是我写的代码。因代码不规范(尤其变量命名方面,没有遵守匈牙利命名规则)被涮。受linux影响啊。
  1. /*只输出字符串中第一个符合条件的域,第二个不能输出。*/
  2. #include<stdio.h>;
  3. #include<string.h>;
  4. #include<ctype.h>;
  5. #include<stdlib.h>;
  6. #include<time.h>;

  7. main(int argc,char *argv[])
  8. {
  9.         int iGetItem(char *,char *,char *,int *);
  10.         void log(char *,char *);

  11.         char *item_src;
  12.         char *item_code;
  13.         char item_value[1000];
  14.         int *item_len;
  15.         int i,temp,length;

  16.         item_len=&

  17.         /*检查参数个数*/

  18.         if(argc!=3){
  19.                 fprintf(stderr,"You must input two parameter");
  20.                 exit(1);
  21.         }

  22.         item_src=argv[1];
  23.         item_code=argv[2];

  24.         /*下面代码检字符串中字符个数是否大于6,小于6则没有完整的域*/
  25.         for(i=0;i<6;i++){
  26.                 if((*item_src)=='\0'){
  27.                         fprintf(stderr,"the string must more than 6 character");
  28.                         exit(1);
  29.                 }
  30.                 item_src++;
  31.         }
  32.         item_src=argv[1];

  33.         /*下面代码检查第二个参数是否是三位数字*/

  34.         for(i=0;i<3;i++){
  35.                 if(isdigit(*(item_code+i))==0){
  36.                         fprintf(stderr,"the argv[2] must be three numbers");
  37.                         exit(1);
  38.                 }
  39.         }

  40.         item_code=argv[2];

  41.         memset(item_value,'\0',sizeof(item_value));
  42.         iGetItem(item_src,item_code,item_value,item_len);

  43.         printf("Item[%s],value=[%s],length=%d",item_code,item_value,*item_len);

  44.         /*调用日志函数*/
  45.         log(argv[1],argv[2]);
  46.         exit(0);
  47. }




  48. int iGetItem(char *szSrc,char *szItemCode,char *szItemValue,int *piItemlen)
  49. {
  50.         char *item_point_2;
  51.         char *item_point_end;
  52.         char *item_point_oth;
  53.         char *item_code_2;
  54.         char *item_value_2;
  55.         int i;
  56.         int length_2;

  57.         item_value_2=szItemValue;
  58.         item_code_2=szItemCode;
  59.         item_point_2=szSrc;
  60.         item_point_end=szSrc+strlen(szSrc)-6;

  61.         /*item_point_2不可以指向字符串的最后5个字符,没有完整的域*/

  62.         for(;item_point_2<item_point_end;){

  63.                 /*
  64.                 *
  65.                 *下面查找域码的首地址,若此域码域长或域内容不合条件,则跳出进行下次查找
  66.                 *
  67.                 */

  68.                 item_point_oth=strstr(item_point_2,item_code_2);

  69.                 if(item_point_oth==NULL||item_point_oth>;item_point_end){
  70.                         printf("No such item\n");
  71.                         exit(0);
  72.                 }

  73.         item_point_2=item_point_oth;

  74.         item_point_oth+=3;   /*使item_point_oth指向域长的第一个字符*/

  75.         /* 检查域长是否为三位数字*/

  76.         for(i=0;i<3;i++){
  77.                 if(isdigit(*(item_point_oth+i))==0)
  78.                         goto loop;                     /*域长不符合条件,跳出进行下次查找*/
  79.         }

  80.         /*求域长*/

  81.         length_2=((int)(*(item_point_oth))-48)*100+((int)(*(item_point_oth+1))-48)*10+((int)(*(item_point_oth+2))-48);

  82.         *piItemlen=length_2; /*赋值给main函数中的length*/

  83.         /*把域长后域长位字符复制到字符数组item_value_2 */
  84.                 item_point_oth+=3;
  85.                 for(i=0;i<length_2;i++){
  86.                         if(*(item_point_oth)=='\0'){
  87.                                 memset(szItemValue,'\0',i);
  88.                                 item_value_2=szItemValue;
  89.                                 goto loop;              /*域内容不符合条件,跳出进行下次查找*/
  90.                         }
  91.                         *(item_value_2++)=*(item_point_oth++);
  92.                 }
  93.                 return(1);
  94.                 loop: item_point_2++;
  95.         }
  96. }

  97. void log(char *point_a,char *point_b)
  98. {
  99.         struct tm *tm_ptr;
  100.         time_t the_time;
  101.         char filename[12];
  102.         char temp[2];
  103.         FILE *fp;
  104.         char *point_1;
  105.         char *point_2;

  106.         (void)time(&the_time);
  107.         tm_ptr=localtime(&the_time);

  108.         /*把日期转换为文件名*/
  109.         sprintf(filename,"%04d",tm_ptr->;tm_year+1900);
  110.         strcat(filename,"");/*linux中必须此代码,否则执行.exe产生错误*/

  111.         sprintf(temp,"%02d",tm_ptr->;tm_mon+1);
  112.         strcat(filename,temp);

  113.         sprintf(temp,"%02d",tm_ptr->;tm_mday);
  114.         strcat(filename,temp);
  115.         strcat(filename,".log");

  116.         if((fp=fopen(filename,"a+"))==NULL){
  117.                 fprintf(stderr,"Cannot open %s",filename);
  118.                 exit(1);
  119.         }

  120.         point_1=point_a;
  121.         point_2=point_b;

  122.         for(;*point_1!='\0';point_1++)
  123.                 fprintf(fp," %d ",*point_1);
  124.         fprintf(fp,"   %s\n",point_a);

  125.         for(;*point_2!='\0';point_2++)
  126.                 fprintf(fp," %d",*point_2);
  127.         fprintf(fp,"   %s\n",point_b);

  128.         fclose(fp);
  129. }
复制代码
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP