freepeople性欧美熟妇, 色戒完整版无删减158分钟hd, 无码精品国产vα在线观看DVD, 丰满少妇伦精品无码专区在线观看,艾栗栗与纹身男宾馆3p50分钟,国产AV片在线观看,黑人与美女高潮,18岁女RAPPERDISSSUBS,国产手机在机看影片

正文內(nèi)容

程序設計基礎第6章-資料下載頁

2025-01-06 18:28本頁面
  

【正文】 ,整個成績表就是降序排列的成績表 。 如無序成績表: 67,34,90,88,55,74,95,82,43,92 92 43 82 95 74 55 88 90 34 67 34 43 55 67 74 82 88 90 92 95 92 43 82 67 74 55 88 90 34 95 34 43 55 67 74 82 88 90 92 95 34 43 82 67 74 55 88 90 92 95 34 43 55 67 74 82 88 90 92 95 尋找最高成績的程序 , 其核心片段如下 max = scores[1]。 max_index = 1。 for (i = 2。 i = 10。 i ++) { if (scores[i] max) { max = scores[i]。 max_index = i。 } } 成績表存放在數(shù)組 scores[11]中 , 從下標 1的位置開始存放 。用變量 max保存當前的最大值 , 用變量 max_index保存當前的最大值所在的位置 。 外循環(huán)變量 j表示處理第幾個位置 , 內(nèi)循環(huán)變量 i控制尋找當前循環(huán)中的最大值 。 max_index= scores[max_index]=67 1) i=2 ∵ scores[2]=34 scores[max_index]=67∴ max_index=1不變 2) i=3 ∵ scores[3]=90 scores[max_index]=67∴ max_index=3 3) i=4 ∵ scores[4]=88 scores[max_index]=90∴ max_index=3不變 4) i=5 ∵ scores[5]=55 scores[max_index]=90∴ max_index=3不變 5) i=6 ∵ scores[6]=74 scores[max_index]=90∴ max_index=3不變 6) i=7 ∵ scores[7]=95 scores[max_index]=90∴ max_index=7 7) i=8 ∵ scores[8]=82 scores[max_index]=95∴ max_index=7不變 8) i=9 ∵ scores[9]=43 scores[max_index]=95∴ max_index=7不變 9) i=10 ∵ scores[10]=92 scores[max_index]=95∴ max_index=7不變 結果: max_index= scores[max_index]=95 確定算法: 循環(huán)變量 j的初值取 1 如果 j = 10, 循環(huán)結束轉(zhuǎn)到 10 用變量 max保存 scores[j]的值 , max_index的初值取 j 循環(huán)變量 i的初值取 j + 1 如果 i 10, 轉(zhuǎn)到 8 如果 scores[i] max, 用 scores[i]的值刷新 max的值 , 讓max_index記下 i的值 循環(huán)變量 i加 1, 轉(zhuǎn)回到 5 交換 scores[max_index]和 scores[j]的值 循環(huán)變量 j加 1, 轉(zhuǎn)回到 2 輸出 scores中的 10個成績數(shù)據(jù) include iostream using namespace std。 int main() { int scores[11] = {0,67,34,90,88,55,74,95,82,43,92}。 int max,max_index,i,j。 for (j = 1。 j 10。 j ++) { max = scores[j]。 max_index = j。 for (i = j + 1。 i = 10。 i ++) { if (scores[i] max) { max = scores[i]。 max_index = i。 } } scores[max_index] = scores[j]。 scores[j] = max。 } cout 排序結果 。 for (j = 1。 j = 10。 j ++) { cout scores[j] 。 } cout endl。 return 0。 } 最簡單的一種加密方法:約定一個字符變換表 , 把字符串中的每個字符都按變換表轉(zhuǎn)換成另一個字符 。 例題:編寫程序 , 實現(xiàn)功能:從鍵盤輸入一個完全由小寫字母組成的字符串 , 用上述的簡單方法加密 。 輸出加密后的字符串 。 確定算法: 先用一個字符型數(shù)組 list依次保存 abcdxyz這 26個小寫字母的轉(zhuǎn)換結果字符 。 顯然這個數(shù)組中的 26個字符不能有重復 , 否則將導致兩個不同的原始字母都轉(zhuǎn)換成同一個字符 , 以后無法正確解密 。 輸入原始字符串到 str 循環(huán)變量 i取初值 0 如果 str[i]的值是 ’ \0?, 轉(zhuǎn)到 7 str[i]的值減去 97, 得到這個字母在小寫字母表中的序號 ,用變量 j保存這個序號 以 j的值作為下標 , 在 list中得到這個字母的轉(zhuǎn)換結果 , 保存到 str[i]取代原始字母 i加 1, 轉(zhuǎn)回到 3, 進行下一個字母的加密轉(zhuǎn)換 輸出轉(zhuǎn)換后的 str, 結束運行 include iostream using namespace std。 int main() { char list[27] = kczuytmxsejdlribnhvawofpgq。 char str[80]。 int i,j。 cout 請輸入一小寫字母串 ( 長度小于 80) : 。 cin str。 i = 0。 while (str[i] != 39。\039。) { j = str[i] 97。 str[i] = list[j]。 i ++。 } cout 加密成為: str \n。 return 0。 } ?字符串連接函數(shù) strcat 格式: strcat(字符數(shù)組 1,字符數(shù)組 2) 功能:把字符數(shù)組 2連到字符數(shù)組 1后面 返值:返回字符數(shù)組 1的首地址 說明: ?字符數(shù)組 1必須足夠大 ?連接前 ,兩串均以‘ \0’結束 。連接后 ,串 1的‘ \0’取消 , 新串最后加‘ \0’ ?字符串拷貝函數(shù) strcpy 格式: strcpy(字符數(shù)組 1,字符串 2) 功能:將字符串 2,拷貝到字符數(shù)組 1中去 返值:返回字符數(shù)組 1的首地址 說明: ?字符數(shù)組 1必須足夠大 ?拷貝時‘ \0’一同拷貝 ?不能使用賦值語句為一個字符數(shù)組賦值 例 char str1[20],str2[20]。 str1={“Hello!”}。 (?) str2=str1。 (?) ?常用的字符串處理函數(shù)包含在頭文件 include string 例 strcpy與 strcat舉例 include string include iostream using namespace std。 int main() { char destination[25]。 char blank[] = , c[]= C++, visual[] = Visual。 strcpy(destination, visual)。 strcat(destination, blank)。 strcat(destination, c)。 coutdestinationendl。 return 0。 } Visual C++ V s u a C + + 0 1 2 3 4 5 6 7 8 9 i \0 24 ……. l 10 \0 24 ……. ……. \0 ……. …... ?字符串比較函數(shù) strcmp 格式: strcmp(字符串 1,字符串 2) 功能:比較兩個字符串 比較規(guī)則:對兩串從左向右逐個字符比較( ASCII碼), 直到遇到不同字符或‘ \0’為止 返值:返回 int型整數(shù), a. 若字符串 1 字符串 2, 返回 負整數(shù) b. 若字符串 1 字符串 2, 返回 正整數(shù) c. 若字符串 1== 字符串 2, 返回 零 說明: 字符串比較不能用“ ==” ,必須用 strcmp ?字符串長度函數(shù) strlen 格式: strlen(字符數(shù)組 ) 功能:計算字符串長度 返值:返回字符串實際長度,不包括‘ \0’在內(nèi) 例 對于以下字符串, strlen(s)的值為: ( 1) char s[10]={39。A39。,39。\039。,39。B39。,39。C39。,39。\039。,39。D39。}。 ( 2) char s[ ]=\t\v\\\0will\n。 ( 3) char s[ ]=\x69\082\n。 答案: 1 3 1 include include void main() { char str1[] = Hello!, str2[] = How are you?,str[20]。 int len1,len2,len3。 len1=strlen(str1)。 len2=strlen(str2)。 if(strcmp(str1, str2)0) { strcpy(str,str1)。 strcat(str,str2)。 } else if (strcmp(str1, str2)0) { strcpy(str,str2)。 strcat(str,str1)。 } else strcpy(str,str1)。 len3=strlen(str)。 coutstrendl。 coutLen1=len1,Len2=len2,Len3=len3endl。 } 例 strcmp與 strlen舉例 How are you?Hello! Len1=6,Len2=12,Len3=18 例 比較 int a[2][3]={{5,6},{7,8}}。 與 int a[2][3]={5,6,7,8}。 5 6 0 7 8 0 5 6 7 8 0 0 例 int a[][10]。 float f[2][]={ ,}。 例 int a[5]。 a={2,4,6,8,10}。 例 int a[10]。 float i=3。 a[i]=10。 例 char name[0]。 float weight[]。 int array[100]。 例 char str[]=“Hello”。 char str[]={?H?,?e?,?l?,?l?,?o?}。 h e l l o 0 2 3 1 4 h e l l o \0 0 2 3 1 4 5 練習 教學與實驗輔導(第 3版)實驗 6
點擊復制文檔內(nèi)容
醫(yī)療健康相關推薦
文庫吧 www.dybbs8.com
備案圖鄂ICP備17016276號-1