編程題很簡單。整個試卷結構爲:前端
1、問答題:編程
對前端的理解,瞭解哪些框架庫?json
2、在線編程題:身份證分組框架
以下第一道:身份證分組優化
3、在線編程題:身份證分組、統計字符、酒店價格(三選二)spa
以下第二三四道題中三選二做答。prototype
我也搞不懂爲何有兩部分編程題~~~下面詳細說一說編程題目及JS代碼實現:code
1 var line; 2 while(line = read_line()){ 3 while(line.indexOf(" ") != -1){ 4 line = line.replace(" ",""); 5 } 6 if(line.length <= 6){ 7 print(line); 8 } 9 else if(line.length > 6 && line.length <= 14){ 10 var line1 = line.substring(0,6); 11 var line2 = line.substring(6); 12 print(line1 + " " + line2); 13 } 14 else if(line.length > 14 && line.length <= 18){ 15 var line1 = line.substring(0,6); 16 var line2 = line.substring(6,14); 17 var line3 = line.substring(14); 18 print(line1 + " " + line2 + " " + line3); 19 } 20 }
1 var line; 2 while(line = read_line()){ 3 while(line.indexOf(".") != -1){ 4 line = line.split("."); 5 print(line[line.length-1]); 6 } 7 }
1 function find (obj, key) { 2 if (! typeof obj === 'object') { 3 return false; 4 } 5 if (key in obj) { 6 return true; 7 } 8 else { 9 return false; 10 } 11 } 12 var line; 13 while(line = read_line()){ 14 if(Object.prototype.toString.call(line)==='[object String]'){ 15 while(line.indexOf(" ") != -1){ 16 line = line.replace(" ",""); 17 } 18 var json = {}; 19 for(var i = 0; i < line.length; i++){ 20 if (!find(json, line[i])){ 21 json[line[i]] = 1; 22 } 23 else if(find(json, line[i])) { 24 json[line[i]] = json[line[i]] + 1; 25 if (json[line[i]] == 3&&((line[i]<='z'&&line[i]>='a')||(line[i] <= 'Z'&&line[i] >= 'A'))){ 26 print(line[i]); 27 break; 28 } 29 else { 30 continue; 31 } 32 } 33 } 34 } 35 }