Exercise 3-3

xiaoxiao2021-03-06  53

#include #include

/ * Writing a function char * eXpand (const char * ss, char * DS), which extends the string SS like AZ, which extends to the equivalent full list Abcdef ... z. Functions can handle cases of cases and numbers, and can process similar situations such as ABC, A-Z0-9 and -AZ. As the leading and trailing - character is placed in place. Several samples: AF> Abcdeff-a> fedcbaa -fa> Abcdefedcbaa-a> a-aa-9-0> A-9876543210A - B> A - BAC> -ABCA-A> AA AA AA Amide> The right side is the converted character * / char * eXpand. Const char * s, char * ds) {char * DS_HEAD = DS; const char * iter, * iter_l; char TEMP;

IF (ss == null) return null; if (ds == null) return null; / **** Abnormally !!! ******* / if (ss == DS) Return null; / * error Can not modify SS by DS, protect the original SS * / / ******************************************** *********************** / if (* ss == '-') * DS = * ss ; / * When the first position is' - 'time * / for (; * ss! =' / 0 '; ss ) {if (* ss ==' - ') {{= ss-1; ore_l = ss 1;

IF (* iter_l> = '0' && * ore_l <= '9' && * t> = '0' && * iter <= '9' && * iter! = * ore_l) {/ * - Number **** *********** ******************************* / if (* iter <* ore_l) {/ * ascending 0-9 * / --DS; for (Temp = * ip; Temp <* ip_l; Temp ) {* (DS ) = Temp;} Continue;} / * Descending 9-0 * / --DS; for (Temp = * iter; TEMP > * iter_l; temp -) {* (ds ) = Temp;} Continue;} / * Number end ************ ************** ********* / ELSE if (* iter_l> = 'a' && * ore_l <= 'z' && * t> = 'a' && * iter <= 'z' && * t! = * Iter_l) {/ * - lowercase letters ******************************* / if (* iter <* ore_l) {/ * Ascending AZ * / - DS; for (Temp = * ip; Temp <* ip) {* (DS ) = Temp;} Continue;} / * Descending ZA * / --DS; for (TEMP = * iter ; Temp> * iter_l; Temp -) {* (DS ) = Temp;} Continue;} / ****** lowercase letters end **** ************** ******** / ELSE IF (* iter_l> = 'a' && * iter_l <= 'z' && * i> = 'a' && * iter <= 'z' && * iter! = * ITer_L ) {/*-uppercase letter********** **************** **** / if (* iter <* iter_l) {/ * Ascending AZ * / --DS; for (Temp = * ip; Temp <* ip_l; temp ) {* (DS ) = Temp;} Continue; / * Descending ZA * / --DS; for (Temp = * ip; Temp> * Iter_L; Temp -) {* (DS ) = Temp;} Continue;} / **** Club End **** * ******************** /

Else {/ * is not, copy-* / * (ds ) = '-';}} / * if end * / else {/ * is copied by the original sample * / * (DS ) = * ss;}} / * FOR end * /

/ * DS final position plus '/ 0' * / * DS = '/ 0';

Return DS_HEAD;} / * There is a program in this function that can be used in the inside, but considering the waste of the parameter transfer, there is no writing, so there is a bit redundant * / int main (void) {char A [100000] = "------ A-ZZ-AA-ZZ-A0-99-09-AA-B ------ A"; Char B [100000]; Char * C; Printf "1:% S / N", A); C = Expand (A, B); Printf ("2:% S / N", C); Printf ("3:% S / N", Expand (A, b)); system ("pause");

Return 0;}

转载请注明原文地址:https://www.9cbs.com/read-116531.html

New Post(0)