第二十五題(找出字串中最長的數字串)

2021-09-30 11:07:56 字數 731 閱讀 2757

第25題:

寫乙個函式,它的原形是int continumax(char *outputstr,char *intputstr)

功能:在字串中找出連續最長的數字串,並把這個串的長度返回,

並把這個最長數字串付給其中乙個函式引數outputstr所指記憶體。

例如:"abcd12345ed125ss123456789"的首位址傳給intputstr後,函式將返回9,

outputstr所指的值為123456789

#include "stdafx.h"

#include#include#include#include#include #includeusing namespace std;

namespace ms100p_25

int i = 0, maxlen = 0, maxbegin=0, j = 0;

while (inputstr[i] != '\0')

i = i + j;

j = 0;

} for (i = 0; i < maxlen; i++) //複製最大長度數字串到輸出字串中

outputstr[i] = inputstr[maxbegin + i];

outputstr[i] = '\0';

} void test() }

int _tmain(int argc, _tchar* ar**)

執行結果:

第二十五題 把陣列排成最小的數

輸入乙個正整數陣列,把陣列裡所有數字拼接起來排成乙個數,列印能拼接出的所有數字中最小的乙個。例如輸入陣列,則列印出這三個數字能排成的最小數字為321323。解題思路 先將整型陣列轉換成string陣列,然後將string陣列排序,最後將排好序的字串陣列拼接出來。關鍵就是制定排序規則。排序規則如下 若...

找出字串中最長的子串

include includevoid fun1 char a int main void puts bye return 0 void fun1 char p unsigned int i unsigned int len word unsigned int len max 0 unsigned ...

找出字串中最長的子串

include includevoid fun1 char a int main void puts bye return 0 void fun1 char p unsigned int i unsigned int len word unsigned int len max 0 unsigned ...