北京四维图新科技股份有限公司招聘面试精选试题与答案

使用re.match函数进行正则表达式匹配时,如果指定的匹配选项中包括re.MULTILINE,则会对每一行开头的若干字符作匹配。()

此题为判断题(对,错)。


正确答案:错误


请编写一个函数int pattern_index(char substr[],char str[]),该函数执行含通配符“?”的字符串的查找时,该通配符可以与任一个字符匹配成功。当子串substr在str中匹配查找成功时,返回子串substr在str中的位置,否则返回值为0。要求使用 for循环实现。输出结果如下:

子串起始位置:5

注意:部分源程序已存在文件test20_2.cpp中。

请勿修改主函数main和其他函数中的任何内容,仅在函数pattern_index的花括号中填写若干语句。

文件test20_2.cpp的内容如下:

include<iostream.h>

int pattern_index(char substr[],char str[])

{

}

void main ( )

{

char *substring,*string;

int same;

substring="???gram";

string="this program return index of substring";

same=pattern_index(substring, string);

if(same)

cout<<"子串起始位置: "<<same<<end1;

else

cout<<"匹配不成功" <<end1;

}


正确答案:int pattern_index(char substr[]char str[]) { int ijk; for(i=0;str[i];i++) for(j=ik=0;(str[j]==substr[k])||(substr[k]=='?');j++k++) if(!substr[k+1]) return(i); return(0); }
int pattern_index(char substr[],char str[]) { int i,j,k; for(i=0;str[i];i++) for(j=i,k=0;(str[j]==substr[k])||(substr[k]=='?');j++,k++) if(!substr[k+1]) return(i); return(0); } 解析:本题主要考查的是考生使用for循环和一维数组的综合能力。对于复杂查找,往往使用for的多重循环,注意里层for循环用来查找字符串的使用


在Shell变量引用操作符可实现模式匹配替换其中()用来的含义是若pattern匹配变量stra的头部,则删除最长匹配部分并返回剩余部分。

A.${strapattern}

B.${strapattern}

C.${stra%pattern}

D.${stra%%pattern}


正确答案:B


下面的哪些程序段可能导致错误? ( ) Ⅰ: String s = "Gone with the wind"; String t = "good "; String k = s + t; Ⅱ: String s = "Gone with the wind"; String t; t = s[3] + "one"; Ⅲ: String s = "Gone with the wind"; String standard = s.toUpperCase(); Ⅳ: String s = "home directory"; String t = s-"directory":

A.Ⅱ、Ⅲ

B.Ⅱ、Ⅳ

C.Ⅰ、Ⅳ

D.Ⅲ、Ⅳ


正确答案:B
解析:本题是考杳对String操作符的理解和应用。Ⅰ段中,String类型可以直接使用+进行连接运算:Ⅱ段中,String是一种Object,而不是简单的字符数组,不能使用下标运算符取其值的某个元素,错误;Ⅲ段中, toUppelCase0方法是String对象的一个方法,作用是将字符串的内容全部转换为大写并返回转换后的结果(String类型);IV段中,String类型不能进行减(—)运算,错误。


正则表达式模块re的match()方法是从字符串的开始匹配特定模式,而search()方法是在整个字符串中寻找模式,这两个方法如果匹配成功则返回match对象,匹配失败则返回空值None。

此题为判断题(对,错)。


正确答案:√


常见的HTTP状态码有哪些?可用的回答 : 200 OK 301 Moved Permanently 302 Found 304 Not Modified 307 Temporary Redirect 400 Bad Request 401 Unauthorized 403 Forbidden 404 Not Found 410 Gone 500 Internal Server Error 501 Not Implemented

Python里面match()和search()的区别?可用的回答 :re模块中match(pattern,string,flags),检查string的开头是否与pattern匹配。re模块中research(pattern,string,flags),在string搜索pattern的第一个匹配值。

说一说redis-scrapy中redis的作用?可用的回答 : 它是将scrapy框架中Scheduler替换为redis数据库,实现队列管理共享。 优点: 可以充分利用多台机器的带宽; 可以充分利用多台机器的IP地址。

数据库的优化?可用的回答 : 1. 优化索引、SQL 语句、分析慢查询; 2. 设计表的时候严格根据数据库的设计范式来设计数据库; 3. 使用缓存,把经常访问到的数据而且不需要经常变化的数据放在缓存中,能节约磁盘IO; 4. 优化硬件;采用SSD,使用磁盘队列技术(RAID0,RAID1,RDID5)等; 5. 采用MySQL 内部自带的表分区技术,把数据分层不同的文件,能够提高磁盘的读取效率; 6. 垂直分表;把一些不经常读的数据放在一张表里,节约磁盘I/O; 7. 主从分离读写;采用主从复制把数据库的读操作和写入操作分离开来; 8. 分库分表分机器(数据量特别大),主要的的原理就是数据路由; 9. 选择合适的表引擎,参数上的优化; 10. 进行架构级别的缓存,静态化和分布式; 11. 不采用全文索引; 12. 采用更快的存储方式,例如 NoSQL存储经常访问的数据

说一下Django,MIDDLEWARES中间件的作用?可用的回答 : 中间件是介于request与response处理之间的一道处理过程,相对比较轻量级,并且在全局上改变django的输入与输出。

scrapy的优缺点?为什么要选择scrapy框架?可用的回答 : 优点: 采取可读性更强的xpath代替正则强大的统计和log系统 同时在不同的url上爬行 支持shell方式,方便独立调试 写middleware,方便写一些统一的过滤器 通过管道的方式存入数据库 缺点: 基于python爬虫框架,扩展性比较差,基于twisted框架, 运行中exception是不会干掉reactor,并且异步框架出错后是不会停掉其他任务的,数据出错后难以察觉

Python中的lambda是什么?可用的回答 :它是一个单独的表达式匿名函数,通常用作内联函数。

scrapy和requests的使用情况?可用的回答 : requests 是 polling 方式的,会被网络阻塞,不适合爬取大量数据 scapy 底层是异步框架 twisted ,并发是最大优势

 

以下是替换字符串中制定字符的函数过程: Function sReplace (SearchLine As String,SearchFor As String,Replace With As String) As String Dim vSearchLine As String,found As Integer found=InStr (SearchLine,SearchFor):vSearchLine=SearchLine If found <>0 Then vSearchLine=" " If found>1 Then vSearchLine=Left (SearchLine,found -1) vSearchLine=vSearchLine+ReplaceWith End If If(表达式)<Len(SearchLine)Then vSearchLine=vSearchLine+Rights (SearchLine,Len (SearchLine) ―found―Len(SearchFor)+1) End If End If sReplace=vSeachLine End Function过程中的“表达式”应为( )。

A.found

B.found-1

C.found+Len(SearchFor)

D.found+Len(SearchFor)-1


正确答案:D


本程序的功能是,根据用户输入的文件名,在相应的文件内容中查找匹配给定模式的字符串,并将这些字符串显示出来。模式串为“href="…"”。请填写横线处的内容。

注意:请勿改动main()主方法和其他已有语句内容,仅在横线处填入适当语句。

import java.io.*;

import java.util.regex.*;

import javax.swing.*;

public class Example2_10

{

public static void main(String [] argv)

{

final String patternString =

"href\\s*=\\s*(\"[^\"]*\"|[^\\s>])\\s*;

String fileName ;

try

{

System. out. print ( "请输入html 文件的文件名: ");

InputStreamReader in = new InputStreamReader(System.in);

BufferedReader imput = new BufferedReader(in);

fileName = imput.readLine();

if(fileName.equals(" "))

return;

StringBuffer buffer = new StringBuffer();

File file = new File(fileName);

FileInputStream readfile = new FileInputStream(file);

for(int c = 0; (c = readfile.read()) != -1; )

buffer.append((char)c);

Pattern pattern = Pattern.compile(

_____________ Pattern.CASE_INSENSITIVE);

Matcher matcher =________;

while (marcher. find ())

{

int start = matcher.start();

int end = matcher.end();

String match = buffer.substring(start, end);

System.out.println (match);

}

}

catch (Exception excption)

{

System. out.println (excption. getMessage ());

}

System.exit(O);

}

}


正确答案:patternString pattern.matcher(buffer)
patternString pattern.matcher(buffer) 解析:本题考查知识点:输入输出流和正则表达式解题思路:程序首先使用InputStreamReader的实例“in”从标准输入中获取用户输入的文件名,并将结果存放在“fileName”字符串中。if语句用来判断用户输入的文件名是否为空,如果为空则退出程序,不做任何处理。然后根据文件名读取相应的文件内容存放在StringBuffer的实例“buffer”中。然后建立起与正则表达式对应的模式对象“pattem”,并与“buffer”帮定,生成一个匹配器“matcher”。最后使用while循环查找到相应的字符串。
Patter的compile方法用来将正则表达式编译成模式对象。compile方法的第一个参数是正则表达式字符串,所以第一个空的答案是“patternString”。
第二个空用来建立一个匹配器。模式对象建立匹配器的方法是matcher(string),其中string是需要做模式匹配的兑现,本题中需要做模式匹配的对象是“buffer”。


在C#中,string str = null 与 string str = “” 请尽量使用文字或图象说明其中的区别。


正确答案:
答:string str = null 是不给他分配内存空间,而string str =  给它分配长度为空字符串的内存空间。


A pattern according to which vessels and / or aircraft may conduct a co-ordinated search is a ___________.

A.Research pattern

B.Research mode

C.Search pattern

D.Search and rescue mode


正确答案:C
船舶和航空器进行协调搜救的模式叫做搜寻模式。


如须查询四字地名代码以ZB开头的机场,应在Aerodrome Code Search String中填写().

  • A、ZB
  • B、ZB*
  • C、ZBPE
  • D、ZB%

正确答案:D

更多 “北京四维图新科技股份有限公司招聘面试精选试题与答案” 相关考题
考题 单选题()is not a search pattern.A Williamson TurnB ParallelC SectorD zig-zag maneuver正确答案:C解析:暂无解析

考题 在Shell变量引用操作符可实现模式匹配替换其中()用来的含义是若pattern匹配变量stra的头部,则删除最长匹配部分并返回剩余部分。A、${stra #pattern}B、${stra##pattern }C、${stra%pattern}D、${stra%%pattern}正确答案:B

考题 string模块中的属性有哪些()。A、ascii_lettersB、digitsC、inD、input正确答案:A,B

考题 假设re模块已成功导入,并且有pattern=re.compile(’^’+’/.’.join([r’/d{1,3}’foriinrange(4)])+’$’),那么表达式pattern.match(’192.168.1.103’)的值为None。正确答案:错误

考题 多选题下面哪段语法执行正确()AString s = Gone with the wind;String t =  good ;String k = s + t;BString s = Gone with the wind;String t; t = s[3] + one;CString s = Gone with the wind;String standard = s.toUpperCase();DString s = home directory;String t = s - directory;正确答案:A,C解析:暂无解析

考题 在python中,string模块有digits属性。正确答案:正确

考题 Which of the following fragments might cause errors?()    A、 String s = "Gone with the wind";String t = " good ";String k = s + t;B、 String s = "Gone with the wind";String t;t = s[3] + "one";C、 String s = "Gone with the wind";String standard = s.toUpperCase();D、 String s = "home directory";String t = s - "directory";正确答案:B,D

考题 request对象可以使用()方法获取表单中某输入框提交的信息。A、getParameter(String s)B、getValue(String s)C、getParameterNames(String s)D、getParameterValue(String s)正确答案:A

考题 下面哪个方法能判断字符串中是否存在和指定正则表达式匹配的字符串;是则返回true,否则返回false:()A、RegExp 对象的 test()方法B、RegExp 对象的 exec()方法C、String 对象的 search()方法D、String 对象的 match()方法正确答案:A

考题 判断题假设re模块已成功导入,并且有pattern=re.compile(’^’+’/.’.join([r’/d{1,3}’foriinrange(4)])+’$’),那么表达式pattern.match(’192.168.1.103’)的值为None。A 对B 错正确答案:错解析:暂无解析