金山軟件軟件工程筆試題

時間:2018-12-31 12:00:00 資料大全 我要投稿

金山軟件軟件工程筆試題

  一、請你就C/C++或者JAVA代碼行數(shù)、注釋行數(shù)統(tǒng)計工具的實現(xiàn),描述一下:

金山軟件軟件工程筆試題

  1、 需要考慮哪些過濾條件?你如何處理?

  答:過濾條件:(取得每行并去掉兩頭的空格后)

 、趴招,行的長度為0;⑵如果是以//開頭,為注釋行;⑶//在行中,并判斷不是在字符串中,即“”中,為代碼+注釋混合行,//在“”中時為代碼行;⑷如果/*在行中,判斷是否是在“”內(nèi),否則為注釋行,*/不在“”中時是結(jié)束 ;⑸/* */只在一行,判斷行中是否有代碼,無代碼為注釋行,有代碼是混合行;⑹/* */多行,并且/*前無代碼,/*后無代碼,去掉其中空行都是注釋行;⑺/* */多行,/*在代碼后,或*/后有代碼,有混合行;⑻一行中有2個/*并且就1個*/,此行為混合行,其后是注釋行,

金山軟件軟件工程筆試題

。

  2、 怎樣提升這個工具的易用性?

  答:把這個工具設(shè)置成圖形界面,用戶只需輸入文件名或者在文件對話框中選擇文件即可點擊運行輸出結(jié)果。

  本題只需要提供思路文檔,不需要程序代碼。

  二、給定一個自然數(shù)n,試完成如下程序,它輸出不大于n的所有素數(shù)(質(zhì)數(shù))。

  1、 請?zhí)峁┏绦虼a,以及思路文檔。

  答:思路:求出一個數(shù)j的平方根sqrt(j),將j除以2~sqrt(j)之間的數(shù),只要除盡一次,就不是素數(shù),之后數(shù)j加2。

  #include

  #include

  void main()

  { int N=1000;

  int i,j,k,m=0;

  for(j=1;j

  { k=(int)sqrt(j); /*求平方根*/

  for(i=2;i<=k;i++)

  { if(j%i==0) /*只要除盡一次,就不是素數(shù)*/

  break;

  }

  if(i>k) /*/除到k一直沒除盡,是素數(shù)*/

  printf(“%d “,j);

  }

  }

  3、 請分析一下可以從哪些角度可優(yōu)化該程序的時間性能?

  答:偶數(shù)(除了2)不能為素數(shù);判斷一個數(shù)j是否為素數(shù),只要將其除以2 ~ sqrt(j)之間的素數(shù),更進一步,沒有必要對所有奇數(shù)進行試除,只需對所有sqrt(j)以內(nèi)的所有質(zhì)數(shù)試除就可以了。

  三、高精度乘法

  用戶輸入兩個不大于 256 位的正整數(shù),由程序進行乘法運算,并顯示運算過程與結(jié)果。例:

  輸入:12, 32

  輸出:

  12

  × 32

  ————————

  24

  36

  ————————

  384

  #include

  #include

  #include

  #define max 256

  int A[max],B[max];

  int Alen,Blen;

  int S[max *2];

  void InputAB() //輸入A B

  { int c;

  while (!isdigit(c = getchar())) ;

  Alen=1;

  A[0]= c – ’0′;

  while (isdigit(c = getchar()))

  A[Alen++] = c – ’0′;

  while (!isdigit(c = getchar())) ;

  Blen = 1;

  B[0] = c – ’0′;

  while (isdigit(c = getchar()))

  B[Blen++] = c – ’0′;

  }

  void Print(int Array[], int len) //輸出數(shù)組

  { int i=0;

  while ((i

  i++;

  if (i == len)

  { printf(“0 \n”);

  return;

  }

  for ( ;i < len; i++)

  printf(“%d”,Array[i]);

  printf(“\n”);

  }

  void Mul(int Array[], int len, int n, int Result[], int zeros) //相乘

  { int i;

  for (i = len – 1; i >= 0; i–)

  Result[i+1] = Array[i]*n;

  Result[0] = 0;

  for (i = len; i > 0; i–)

  { if (Result[i] >= 10) //大于10的進位

  { Result[i-1] +=Result[i] / 10;

  Result[i] %= 10;

  }

  }

  for (i = 1; i <= zeros; i++)

  Result[len+i] = 0;

  }

  void Add(int total[], int tlen, const int add[], int alen) //各行相加

  { int i,k = tlen;

  while ((tlen > 0) && (alen > 0)) //相加

  { tlen–;

  alen–;

  total[tlen] += add[alen];

  }

  for (i = k – 1; i>=0; i–)

  if (total[i] >= 10) //大于10的進位

  { total[i - 1] += total[i] / 10;

  total[i] %= 10;

  }

  }

  void main()

  { int i,j;

  int temp[max*2];

  InputAB();

  Print(A,Alen);

  printf(“*”);

  Print(B,Blen);

  printf(“—–\n”);

  for(i = Blen-1; i >= 0; i–)

  { for(j=Blen-i,j>=0;j–) //輸出空格

  { printf(“ ”);

  }

  Mul(A, Alen, B[i], temp, Blen – 1 -i);//B中的一個數(shù)與A的所有數(shù)相乘

  Print(temp, Alen + 1); //輸出相乘過程中的每行

  Add(S, max*2, temp, Alen + Blen – i);//每行相加

  }

  printf(“—–\n”);

  Print(S, max*2);

  }

  }四、輸入一個N進制數(shù),將其轉(zhuǎn)換成 M 進制數(shù)(1

  #include

  #include

  #include

  #include

  #include

  using namespace std;

  int main()

  {

  char digit[16] = {0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F};

  cout <<”輸入待轉(zhuǎn)換整數(shù): “;

  char c;

  char a[80];

  char b[80];

  int i=0,j=0,length;

  while ((c = getchar())!=’\n’) //輸入

  {a[i]=c;

  i++;

  }

  length=i; //輸入的數(shù)的位數(shù) 0~i-1

  for(j=0;j

  { if( a[j]>=’0′&&a[j]<=’9′ )

  b[j] = a[j] – ’0′;

  else if( a[j]>=’a'&&a[j]<=’f’ )

  b[j] = a[j] -’a’ +10;

  else if( a[j]>=’A'&&a[j]<=’F’ )

  b[j] = a[j] -’A’ +10;

  else

  return FALSE;

  }

  cout<<”輸入的'數(shù)是多少進制N:”;

  int n

  cin>>n;

  assert((n>1)&&(n<=16));

  int num=0;

  for(i=0,j=length-1;j>=0;j–,i++)//輸入的數(shù)轉(zhuǎn)成十進制

  {num+=b[i]*pow(n,j);

  }

  cout <<”轉(zhuǎn)換成進制數(shù)M: “;

  int m;

  cin >>m;

  cout <

  assert((m>1)&&(m<=16));

  stack stk;

  char remain;

  while (num!=0)//轉(zhuǎn)成M進制

  {

  remain = digit[num%m];

  stk.push(remain);

  num/= m;

  }

  cout <<”結(jié)果: “;//輸出結(jié)果

  while(!stk.empty())

  {

  cout <

  stk.pop();

  }

  cout <

  return 0;

  }

  五、選答題(以下任選一題):

  1、構(gòu)建一個應(yīng)用程序,它可以顯示剪貼板上所有可用的格式,并且將常規(guī)格式(如文本、圖形)顯示出來,

資料共享平臺

金山軟件軟件工程筆試題》(http://clearvueentertainment.com)。

  2、構(gòu)建一個應(yīng)用程序,它用于顯示一幅透明位圖。即,給定一個背景圖、一個待顯示位圖和一個對應(yīng)于該位圖的屏蔽(mask)圖,將位圖未屏蔽部分顯示在背景圖上。

  3、構(gòu)造一個服務(wù)端程序和一個客戶端程序。它用于通過網(wǎng)絡(luò)將文件從服務(wù)端傳送到客戶機(類似FTP)。或者直接是一個FTP客戶端程序也可,不能使用FTP控件。

  4、構(gòu)造一個應(yīng)用程序,它定時獲取CPU利用率,并且以折線圖的方式動態(tài)顯示出來。

  5、利用UDP把一個文件從一臺機器傳送到另一臺機器。

  6、在某文件中查找指定的單詞,把所有包含此單詞的文本行打印出來,并對找到的單詞作著重顯示(如下劃線或其他顯示方式)的處理。

  6:

  #include

  #include

  #include

  #include

  #include

  #include

  using namespace std;

  int word_find(const char t[], int m, const char s[], int n ,vector& colpos)

  //查找單詞,char t[]為單詞,m單詞長度,char s[]為行,n行的長度,colpos記錄找到單詞所在的位置

  { int i=0,j=0,cnt=0;

  while(j

  { if(i >= m)

  { if(!isalpha(s[j])&&!isalpha(s[j-m-1]))//字符串前后不是字母時是單詞

  { colpos[cnt++] = j – m ;//單詞的第一個字符所在的行下標(biāo)

  i=0; //單詞串下標(biāo)重置為0

  if(cnt == colpos.size())

  colpos.resize(cnt * 2);//長度重設(shè)為原來2倍

  }

  else { i=0; }

  }

  else if (s[j]==t[i])

  { ++i;++j; }

  else

  { j=j-i+1; i=0; } //下標(biāo)后退重新開始匹配

  }

  return cnt;//返回查到的個數(shù)

  }

  int count_string(string source, string target, vector& colpos)

  { int find_cnt = 0;

  find_cnt = word_find(target.c_str(), target.size(), source.c_str(),source.size(),colpos);

  return find_cnt;//返回查到的個數(shù)

  }

  int main()

  {

  string file_name, line;

  vector lines;

  lines.resize(10);

  cout << “Input the file name:”;

  cin >> file_name;

  ifstream in_file; //打開文件

  try{

  in_file.open(file_name.c_str());

  if(!in_file)

  throw(file_name);

  }

  catch(string file_name)

  { cout << “Fatal error: File not found.”<

  exit(1);

  }

  int line_count = 0;//文件行數(shù)

  do{

  getline(in_file, lines[line_count]);

  line_count ++;

  if(line_count == lines.size())//未結(jié)束時行數(shù)設(shè)為原來2倍

  lines.resize(line_count * 2);

  }while(in_file.eof()==0);

  string tag;//要查找的單詞

  vector colpos;//單詞中第一個字符所在位置

  colpos.resize(10);

  do

  {

  cout << “Input the word you want to find(# for quit):”;//輸入要查找的單詞#結(jié)束

  cin >> tag;

  if(tag == “#”)

  { break; }

  int count = 0, line_no = 0 , inline_count;//line_no是行號,第?行

  for(line_no = 0 ;line_no < line_count ; line_no++)

  {

  inline_count = count_string(lines[line_no], tag, colpos);//每行查到的個數(shù)

  count += inline_count; //查到的總數(shù)

  if(inline_count > 0)

  {

  cout << “在第” << line_no<<”行找到”<< inline_count<<”個” <

  cout << ” ,所在位置是 “;

  for(int i = 0 ;i< inline_count ;i++)

  {

  cout << colpos << ‘ ‘;//輸出位置

  }

  cout << endl;

  cout << lines[line_no] << endl;//輸出行,未作著重顯示

  }

  }

  }while(tag != “#”);

  in_file.close();

  return 0;

  }

【金山軟件軟件工程筆試題】相關(guān)文章:

1.金山軟件筆試題

2.金山軟件策劃類筆試題目

3.金山軟件校招筆試題目

4.軟件工程筆試題1

5.軟件工程師筆試題

6.德爾福軟件工程師筆試題

7.VC軟件工程師筆試題

8.軟件工程師筆試題集