1. write a function. The original form is int continumax (char * outputstr, char * intputstr)
function:
Find the longest consecutive numeric string , return the length of the string, and pay the longest numeric string to the memory specified by one of the function parameters outputstr. For example, after the first address of "abcd12345ed125ss123456789" is passed to intputstr, the function returns
9, outputstr refers to 123456789.
#Include <Stdio.H> #Include <Stdlib.H> #Include <String.H> Int Findmax_numstr ( Char * Outputstr , Char * Inputstr ) { Char * In = Inputstr , * Out = Outputstr , * Temp ; Char * Final ; Int Count = 0 ; Int Maxlen = 0 ; Int I ; While ( * In! = '\ 0' ) { If ( * In > 47 & & * In < 58) { For ( Temp = In ; * In > 47 & & * In < 58 ; In + + ) Count + + ; } Else In + + ; If ( Maxlen < Count ) { Maxlen = Count ; Count = 0 ; Final = Temp; } }
For ( I = 0 ; I < Maxlen ; I + + ) { * Out = * Final ; Out + + ; Final + + ; } * Out = '\ 0' ; Return Maxlen ; }
Void Main ( Void ) { Char Input [ ] = "Abc123def123456eec123456789dd" ; Char Output [ 50 ] = { 0 } ; Int Maxlen ; Maxlen = Findmax_numstr ( Output, Input ) ; Printf ( "The STR % s \ n" , Output ) ; Printf ( "The maxlen is % d \ n" , Maxlen ) ; }
|
2. Ask 1000! There are several zeros before the end;
Find the number N1 of the number that can be divisible by 5 in 1-> 1000, the number N2 of the number that can be divisible by 25, and the number of The number that can be divisible by 125 N3, number of divisible by 625 n4.1000! Number of zeros at the end = N1 + N2 + N3 + N4;
As long as it is the number of 5 at the end, it is multiplied by an even number, and a 0 at the end is multiplied by any number.
The end is 0. If it is a 0, it is certainly able to be divisible by 5. Two zeros are certainly able to be integer 25. Similarly, three zeros can be divisible by the 3rd power of 5, that is, 125.
1000! That is, the multiplication of 1-100 numbers. If all the numbers that can be divisible by 5 are multiplied by an even number, the numbers 0 will appear. For example, can be divisible by 5 or 25, so there are two 0
1000, can be divided by 125, can also be divided by, so calculate three 0
For example, 10! = 1*2*3*4*5*6*7*8*9*10. There are two numbers that can be divided by 5, namely 10 and 5.
5 Multiply by an even number, and a 0 value is displayed when 10 is multiplied by other numbers. Therefore, 10 is displayed! There will be two zeros
#Include <Stdio.H> #DefineNum 1000 Int Find5 ( Int Num ) { Int RET = 0; While ( Num % 5 = = 0 ) { Num / = 5 ; RET + + ; } Return RET ; }
Int Main ( Void ) { Int Result = 0 ; Int I ; For ( I = 5 ; I < = Num ; I + = 5 ) Result + = Find5( I ) ; Printf ( "The total zero number is % d \ n" , Result ) ; Return 0 ; }
|
3. Compile a C function that finds the longest possible substring in a string and consists of the same character.
Char * Search ( Char * Cpsource , Char Ch ) { Char * Cptemp= Null , * Cpdest = Null ; Int Itemp , Icount = 0 ; While ( * Cpsource ) { If ( * Cpsource = = Ch ) { Itemp = 0 ; Cptemp = Cpsource ; While ( * Cpsource= = Ch ) + + Itemp , + + Cpsource ; If ( Itemp > Icount ) Icount = Itemp , Cpdest = Cptemp ; If ( ! * Cpsource ) Break ; } + + Cpsource ; } Return Cpdest ; }
|