<address id="ousso"></address>
<form id="ousso"><track id="ousso"><big id="ousso"></big></track></form>
  1. 同學鼓勵作文

    時間:2025-09-29 08:34:16 同學 我要投稿

    同學鼓勵作文

      一、請你就C/C++或者JAVA代碼行數、注釋行數統計工具的實現,描述一下:

    同學鼓勵作文

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

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

      ⑴空行,行的長度為0;⑵如果是以/pic/pic/pic/*在行中,判斷是否是在“”內,否則為注釋行,*/不在“”中時是結束 ;⑸/* */只在一行,判斷行中是否有代碼,無代碼為注釋行,有代碼是混合行;⑹/* */多行,并且/*前無代碼,/*后無代碼,去掉其中空行都是注釋行;⑺/* */多行,/*在代碼后,或*/后有代碼,有混合行;⑻一行中有2個/*并且就1個*/,此行為混合行,其后是注釋行。

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

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

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

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

      1、 請提供程序代碼,以及思路文檔。

      答:思路:求出一個數j的平方根sqrt(j),將j除以2~sqrt(j)之間的數,只要除盡一次,就不是素數,之后數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) /*只要除盡一次,就不是素數*/

      break;

      }

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

      printf(“%d “,j);

      }

      }

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

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

      三、高精度乘法

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

      輸入: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() /pic/p>

      { 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) /pic/p>

      { 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) /pic/p>

      { 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) /pic/p>

      { 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) /pic/p>

      { int i,k = tlen;

      while ((tlen > 0) && (alen > 0)) /pic/p>

      { tlen–;

      alen–;

      total[tlen] += add[alen];

      }

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

      if (total[i] >= 10) /pic/p>

      { 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–) /pic/p>

      { printf(“ ”);

      }

      Mul(A, Alen, B[i], temp, Blen – 1 -i);/pic/p>

      Print(temp, Alen + 1); /pic/p>

      Add(S, max*2, temp, Alen + Blen – i);/pic/p>

      }

      printf(“—–\n”);

      Print(S, max*2);

      }

      }四、輸入一個N進制數,將其轉換成 M 進制數(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 <<”輸入待轉換整數: “;

      char c;

      char a[80];

      char b[80];

      int i=0,j=0,length;

      while ((c = getchar())!=’\n’) /pic/p>

      {a[i]=c;

      i++;

      }

      length=i; /pic/p>

      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<<”輸入的數是多少進制N:”;

      int n

      cin>>n;

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

      int num=0;

      for(i=0,j=length-1;j>=0;j–,i++)/pic/p>

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

      }

      cout <<”轉換成進制數M: “;

      int m;

      cin >>m;

      cout <

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

      stack stk;

      char remain;

      while (num!=0)/pic/p>

      {

      remain = digit[num%m];

      stk.push(remain);

      num/= m;

      }

      cout <<”結果: “;/pic/p>

      while(!stk.empty())

      {

      cout <

      stk.pop();

      }

      cout <

      return 0;

      }

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

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

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

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

      4、構造一個應用程序,它定時獲取CPU利用率,并且以折線圖的方式動態顯示出來。

      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)

      /pic/p>

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

      while(j

      { if(i >= m)

      { if(!isalpha(s[j])&&!isalpha(s[j-m-1]))/pic/p>

      { colpos[cnt++] = j – m ;/pic/p>

      i=0; /pic/p>

      if(cnt == colpos.size())

      colpos.resize(cnt * 2);/pic/p>

      }

      else { i=0; }

      }

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

      { ++i;++j; }

      else

      { j=j-i+1; i=0; } /pic/p>

      }

      return cnt;/pic/p>

      }

      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;/pic/p>

      }

      int main()

      {

      string file_name, line;

      vector lines;

      lines.resize(10);

      cout << “Input the file name:”;

      cin >> file_name;

      ifstream in_file; /pic/p>

      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;/pic/p>

      do{

      getline(in_file, lines[line_count]);

      line_count ++;

      if(line_count == lines.size())/pic/p>

      lines.resize(line_count * 2);

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

      string tag;/pic/p>

      vector colpos;/pic/p>

      colpos.resize(10);

      do

      {

      cout << “Input the word you want to find(# for quit):”;/pic/p>

      cin >> tag;

      if(tag == “#”)

      { break; }

      int count = 0, line_no = 0 , inline_count;/pic/p>

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

      {

      inline_count = count_string(lines[line_no], tag, colpos);/pic/p>

      count += inline_count; /pic/p>

      if(inline_count > 0)

      {

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

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

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

      {

      cout << colpos << ‘ ‘;/pic/p>

      }

      cout << endl;

      cout << lines[line_no] << endl;/pic/p>

      }

      }

      }while(tag != “#”);

      in_file.close();

      return 0;

      }

    【同學鼓勵作文】相關文章:

    鼓勵同學的作文(精選16篇)01-09

    鼓勵同學的作文(精選13篇)01-13

    鼓勵同學的作文(精選15篇)12-18

    【實用】鼓勵同學的作文9篇03-27

    鼓勵我的同學作文(通用40篇)07-03

    媽媽的鼓勵作文11-30

    微笑的鼓勵作文08-18

    鼓勵的聲音作文07-19

    爸爸的鼓勵作文06-25

    同學情作文-同學作文01-25

    <address id="ousso"></address>
    <form id="ousso"><track id="ousso"><big id="ousso"></big></track></form>
    1. 日日做夜狠狠爱欧美黑人