常見C語言面試題之一 字串代替 字串轉換整數

2021-05-31 21:37:39 字數 1111 閱讀 4157

1.#include "stdafx.h"2.using namespace std;

3.//--------字元替代問題4.char* translate(char* psrc, const char cfindchar, const char* preplacestr, char* ptag) 

5.   

16.              else 

17.               

20.          } 

21.          return ptag; 

22.  } 

23.24.//--------字串轉換為整數25.int myatoi(const char* s)

35.    if(s[i] == '+')

36.       i++;

37.    while(s[i] != '\0')

44.    result = result * flag;

45.    return result;

46.}

47.48.//--------整數轉換為字串49.    void itoa (int n,char s)

50.    while ((n/=10)>0);//刪除該數字59.60.        if(sign<0)

61.           s[i++]='-';

62.        s[i]='\0';

63.64.        for(j=i;j>=0;j--)//生成的數字是逆序的,所以要逆序輸出65.           printf("%c",s[j]);

66.        printf("\n");

67.68.    }

69.int _tmain(int argc, _tchar* argv)

70.; 

74.    char   szrep ="(***)";    

75.    char result[256] = ;

76.    translate(szsrc,'o',szrep,sztag);      

77.    for(unsigned int i=0;iwww.diybl.com):

常見C語言面試題之一 字串代替 字串轉換整數

include stdafx.h using namespace std 字元替代問題 char translate char psrc,const char cfindchar,const char preplacestr,char ptag else return ptag 字串轉換為整數 in...

面試基礎(一) 字串函式

最新更新strncpy strstr函式 1 include2 include3 using namespace std 45 6int my strlen const char str 715 return count 16 1718 19int main 20話說這真的不是很難,要說難一點的還是...

Redis入門之一 字串(string)

redis 中最簡單的資料結構,它既可以儲存文字 比如 hello world 又可以儲存數字 比如整數 10086 和浮點數 3.14 還可以儲存二進位制資料 比如 10010100 redis 為這幾種型別的值分別設定了相應的操作命令,讓使用者可以針對不同的值做不同的處理。為字串鍵設定值 獲取字...