程式設計小練習 4

2021-06-27 21:54:38 字數 1912 閱讀 999

給定乙個字串,當其中出現連續三個相同的小寫字母時,將其變為這個字母的下乙個字母,如果是z,則變為a,如 "aaac" 變為 「bc」。變換後,如果又出現了連續三個相同的小寫字母,則繼續變換。最終的輸出的字元不含有連續三個相等的小寫字母。

#include #include #include int changestring(char *pinstr, char *poutstr)

} if (i == len) flag = false;

for (i = 0; i <= len;)

}*output++ = input[i++];

} *output = '\0';

memset(input, 0, 256);

strcpy(input, poutstr);

if (!flag) break;

output = poutstr;

memset(output, 0, len);

} return 0;

}int main()

找出給定字串中第乙個出現次數最多的字元。

#include bool findchar(char* pinputstring, char* pchar)

return true;

}

將乙個整數反序,並按照指定格式輸出。如-123,輸出"-1 2 3"。

#include #include int processx(int iinput, int& inum, char * strrst, int& ioutput)

std::vectorve;

bool isnegative = false;

if(iinput < 0)

while(iinput != 0)

inum = (int)ve.size();

ioutput = 0;

for(unsigned int i = 0; i < ve.size(); ++i)

if(isnegative)

for(int i = (int)ve.size()-1; i >= 0; --i)

*(--strrst) = '\0';

return 0;

}

字串替換,注意成功返回值。

int processstring( char * strinput,char chsrc,char chdes ,char * stroutput)

*stroutput++ = *strinput++;

} *stroutput = '\0';

if(flag) return 0;

return -1;

}

給定乙個公升序陣列,找出相加等於特定值的兩個數字,任意兩個即可。

bool findtwonumberswithsum(int adata, unsigned int uilength, int sum, int *pnum1, int *pnum2)

} return false;

}

ip 和掩碼的格式為這樣的乙個字串,如:「192.168.0.254」;如屬於,返回1,否則返回 0. 

int issamesubnetwork(char * pcip1, char * pcip2, char * pcsubnetworkmask)

return 1;

}

求乙個 int 數中包含的最大連續遞減數,負數返回 -1。

#include #include int getmaxdegressivenum (int num)

return max;

}

程式設計小練習

檔名稱 test.cpp 完成日期 2016年4月11日 問題描述 ip位址 在日常網路環境中,基本是都在使用b,c兩大類位址,而ade這3類位址都不打可能被使用到。include using namespace std class ip ip位址共4位元組,或者看成結構體所指4部分 unsigne...

程式設計小練習

檔名稱 test.cpp 完成日期 2016年4月11日 問題描述 設計乙個 類,要有 名 威力。在上週的遊戲角色類role基礎上擴充,為每個角色建立乙個 並在攻擊 attack 行為發生時,在其中起作用。include using namespace std class weapon weapon...

程式設計小練習

專案 警察和廚師 1 根據下面的類圖,定義各個類 要求 各個成員函式,只要輸出相關的資訊即可,暫不深究其業務功能 請為各個類增加建構函式 在實現中,可以增加需要的其他函式 自行編制main函式,完成初步的測試 include using namespace std class person priv...