牛客网在线编程之“字符串分割”
生活随笔
收集整理的這篇文章主要介紹了
牛客网在线编程之“字符串分割”
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
?連續輸入字符串,請按長度為8拆分每個字符串后輸出到新的字符串數組;?
?長度不是8整數倍的字符串請在后面補數字0,空字符串不處理。?
以下代碼均根據個人邏輯獨立實現,空間或效率未必最優,歡迎批評指正。
#include <iostream> #include <string> #include <stdio.h>using namespace std;void strCoventFun(char *inStr) {int strLen = 0;while(1){if (inStr[strLen] == '\0'){break;}strLen++;}for (int i=0; i<strLen; i++){if (i>0 && i%8 == 0){cout<<endl;}cout<<inStr[i];}int restNum = strLen%8;if (restNum>0 && restNum<8){for(int j=0; j<8-restNum; j++)cout<<0;cout<<endl;} }int main() {char inStr1[120];gets(inStr1);char inStr2[120];gets(inStr2);strCoventFun(inStr1);strCoventFun(inStr2);return 0; }?
總結
以上是生活随笔為你收集整理的牛客网在线编程之“字符串分割”的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 在线编程题之“明明的随机数”
- 下一篇: 创建多级目录函数MakeSureDire