华为最新笔试题——编程题及答案问题:输入一种字符串,用指针求出字符串的长度。答案:#include int main(){ char str[20], *p; int length=0; printf(“Please input a string: ”); gets(str); p=str; while(*p++) {length++;}printf(“The length of string is %d\n”, length);return 0;}问题:使用 C 语言实现字符串中子字符串的替代描述:编写一种字符串替代函数,如函数名为 StrReplace(char* strSrc, char* strFind, char* strReplace),strSrc 为原字符串,strFind 是待替代的字符串,strReplace 为替代字符串。举个直观的例子吧,如:“ABCDEFGHIJKLMNOPQRSTUVWXYZ”这个字符串,把其中的“RST”替代为“ggg”这个字符串,成果就变成了:ABCDEFGHIJKLMNOPQgggUVWXYZ答案一:#include #include void StrReplace(char* strSrc, char* strFind, char* strReplace);#define M 100;void main(){char s[]="ABCDEFGHIJKLMNOPQRSTUVWXYZ";char s1[]="RST";char s2[]="ggg";StrReplace(s,s1,s2);printf("%s\n",s);}void StrReplace(char* strSrc, char* strFind, char* strReplace){ int i=0; int j; int n=strlen(strSrc); int k=strlen(strFind); for(i=0;i#define MAX 100StrReplace(char *s, char *s1, char *s2) { char *p; for(; *s; s++) { for(p = s1; *p && *p != *s; p++); if(*p) *s = *(p - s1 + s2); }}int main(){ char s[MAX]; //s 是原字符串 char s1[MAX], s2[MAX]; //s1 是要替代的 //s2 是替代字符串 puts("Please input the string for s:"); scanf("%s", s); puts("Please input the string for s1:"); scanf("%s", s1); puts("Please input the string for s2:"); scanf("%s", s2); StrReplace(s, s1, s2); puts("The string of s after displace is:"); printf("%s\n", s); return 0;}答案三:#include #include #include #define M 100void StrReplace(char* strSrc, char* strFind, char* s...