ZKX's LAB

从键盘输入字符串a和字符串b 从键盘输入两个字符串a和b,要求不用库函数strcat把字符串b连接到字符串a之后,请用c需要编程

2021-04-23知识0

c++编程问题 从键盘上输入字符串a和字符串b,并在a串的最小元素后面插入字符串b 123456789101112131415#include<;iostream>;#include<;string>;using namespace std;int main(){ string s,t;cin>;>;s;cin>;>;t;int pos=0;for(int i=1;i();i+)pos=s[pos][i]?pos:i;s.insert(pos+1,t);cout;return 0;}

c语言从键盘输入两个字符串a和b,并在a串中的最大元素后边插入字符串b!有图 就程序 #includeincludeincludeconst char*max(const char*x);int main(void){char string1[1024]={0};字符串1;char string2[1024]={0};字符串2;printf(\"Input string1:\");gets(string1);输入串1;printf(\"Input string2:\");gets(string2);输入串2;char*newstr=(char*)calloc(strlen(string1)+strlen(string2)+1,sizeof(char));创建一个刚好容纳两个串的新串;if。newstr)/检查是否创建成功;{printf(\"内存不足,程序结束。\\n\");exit(1);}const char*m=max(string1);调用max函数取串1内最大元素的地址;int i=0;for;string1[i]。m;i)/串1最大元素之前的内容放入新串;newstr[i]=string1[i];newstr[i]=string1[i];串1最大元素放入新串;strcat(newstr,string2);串2接入新串;strcat(newstr,m+1);串1最大元素之后的内容接入新串;printf(\"The new string is%s\\n\",newstr);输出新串;free(newstr);释放内存;newstr=NULL;放空指针;return 0;}const char*max(const char*x)/返回串中最大元素地址;{const char*m=x[0];指向第一个元素;for(int i=1;x[i]。'\\0';i)/循环到'\\0';if(x[i]>;*m)/若比m当前指向的元素大,m=x[i];让m指向该元素地址;return m;返回最大元素地址;}

从键盘输入两个字符串a和b,要求不用库函数strcat,把字符串b前面的五个字符连接到a 后面#include<;stdio.h>;int main(void){ char a[128],b[128];char*p=a;。

#从键盘输入字符串a和字符串b

随机阅读

qrcode
访问手机版