亚洲av成人无遮挡网站在线观看,少妇性bbb搡bbb爽爽爽,亚洲av日韩精品久久久久久,兔费看少妇性l交大片免费,无码少妇一区二区三区

  免費注冊 查看新帖 |

Chinaunix

  平臺 論壇 博客 文庫
最近訪問板塊
查看: 1610 | 回復: 1
打印 上一主題 下一主題

一個招聘試題,想找初程工作的來試試能力。 [復制鏈接]

論壇徽章:
0
跳轉(zhuǎn)到指定樓層
1 [收藏(0)] [報告]
發(fā)表于 2003-08-16 15:06 |只看該作者 |倒序瀏覽
下面是偶求職是得到的試題。我因代碼不規(guī)范沒能面試。


     C語言測試題

總體說明:
1、 以往我們在招聘過程中,總是收到大量的簡歷,還要花費很多時間進行面試,但是效果并不是很好。采用測試的方法,可以提前鑒別求職人員是否真正具有我們所需要的工作能力。
2、 本公司主要從事銀行方面的應用軟件開發(fā),C語言是必備的開發(fā)工具,所以本測試題必須以C或C++語言完成,具體使用什么工具沒有限制,對于剛畢業(yè)的學生,采用Tubro C也可以。
3、 下面兩道題目是銀行業(yè)務軟件中非常普遍的應用,對于從事過這方面程序開發(fā)的人來說是非常容易的。如果你以前沒有從事過這方面的工作,但是對C語言熟悉,完成這些題目也應該問題不大。



一、 基本庫函數(shù)的使用及簡單的算法

一個字符串,其組成規(guī)律如下:
1、 由若干個域(域的數(shù)目不定)組成。
2、 每個域有三部分構(gòu)成:域代碼(3 bytes)、域長度(3 bytes),域內(nèi)容(長度不定,具體長度等于前面的域長度)。

例如,下面的字符串
123003abc456010123456789005hello
實際上由三個域組成:
第一個域:123003abc,表示域代碼為123,域的長度為3 bytes,域的內(nèi)容為abc
第二個域:4560101234567890,表示域代碼為456,域的長度為10 bytes,域的內(nèi)容為1234567890
第三個域:789005hello,表示域代碼為789,域長度為5,域內(nèi)容為hello

要求:
1、 寫一個函數(shù),能夠從這樣的字符串中取得指定的域內(nèi)容及長度,函數(shù)規(guī)范如下:
int iGetItem(char *szSrc, char *szItemCode, char *szItemValue, int *piItemLen)

參數(shù)定義:
char *szSrc:字符串的首地址
char *szItemCode:需要尋找的域的代碼字符串首地址
char *szItemValue:域內(nèi)容存放的首地址
int *piItemLen:指向一個int型變量的指針,找到相應的域后,將該指針指向的變量賦值為域的長度。
2、 編寫一個main函數(shù),調(diào)用上面的iGetItem函數(shù),測試其效果。
3、 將上述兩個函數(shù)放在test1.c 或 test1.cpp 文件中,編譯成可執(zhí)行文件,文件名為test1.exe。
4、 可以在Windows的命令行環(huán)境下執(zhí)行test.exe,帶兩個參數(shù),第一個是字符串,第二個域代碼,執(zhí)行后顯示出域的內(nèi)容和長度,例如:
輸入 C:\test1.exe 123003abc456010123456789005hello 789
輸出 C:\Item[789],value=[hello],length=5 或 c:\no such item.


二、 記錄運行日志

要求:
1、 在第一題的基礎上,添加一個記錄運行日志的函數(shù)。
2、 日志文件名為yyyymmdd.log,文本文件,該文件存放在可執(zhí)行文件所在的目錄下。
3、 文件名中的yyyymmdd表示年、月、日,取運行時的系統(tǒng)日期,形成文件名。
日志中記錄的數(shù)據(jù)就是運行時的兩個輸入?yún)?shù)。要求這些參數(shù)分別以ASCII碼及字符串形式記錄

論壇徽章:
0
2 [報告]
發(fā)表于 2003-08-16 15:06 |只看該作者

一個招聘試題,想找初程工作的來試試能力。

下面是我寫的代碼。因代碼不規(guī)范(尤其變量命名方面,沒有遵守匈牙利命名規(guī)則)被涮。受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.         /*檢查參數(shù)個數(shù)*/

  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.         /*下面代碼檢字符串中字符個數(shù)是否大于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.         /*下面代碼檢查第二個參數(shù)是否是三位數(shù)字*/

  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.         /*調(diào)用日志函數(shù)*/
  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.                 *下面查找域碼的首地址,若此域碼域長或域內(nèi)容不合條件,則跳出進行下次查找
  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.         /* 檢查域長是否為三位數(shù)字*/

  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函數(shù)中的length*/

  83.         /*把域長后域長位字符復制到字符數(shù)組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;              /*域內(nèi)容不符合條件,跳出進行下次查找*/
  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.         /*把日期轉(zhuǎn)換為文件名*/
  109.         sprintf(filename,"%04d",tm_ptr->;tm_year+1900);
  110.         strcat(filename,"");/*linux中必須此代碼,否則執(zhí)行.exe產(chǎn)生錯誤*/

  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. }
復制代碼
您需要登錄后才可以回帖 登錄 | 注冊

本版積分規(guī)則 發(fā)表回復

  

北京盛拓優(yōu)訊信息技術有限公司. 版權所有 京ICP備16024965號-6 北京市公安局海淀分局網(wǎng)監(jiān)中心備案編號:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年舉報專區(qū)
中國互聯(lián)網(wǎng)協(xié)會會員  聯(lián)系我們:huangweiwei@itpub.net
感謝所有關心和支持過ChinaUnix的朋友們 轉(zhuǎn)載本站內(nèi)容請注明原作者名及出處

清除 Cookies - ChinaUnix - Archiver - WAP - TOP