C++:输入一个字符串,输入一个字符,然后去掉字符串中的该字符,并输出去掉字符后的字符串
编写C++程序,输入一个字符串,输入一个字符,然后去掉字符串中的该字符,并输出去掉字符后的字符串。例如,输入字符串”asdfga”和字符’a’,则输出”sdfg”。是数组...
编写C++程序,输入一个字符串,输入一个字符,然后去掉字符串中的该字符,并输出去掉字符后的字符串。例如,输入字符串”asdfga”和字符’a’,则输出”sdfg”。
是数组这一章的作业题 展开
是数组这一章的作业题 展开
2个回答
展开全部
Please input a string:
abcsda-as
please input the key want to delete:
a
bbcsd--ss
Press any key to continue
#include <iostream>
using namespace std;
main()
{
int i,j,nLen;
char str[100]="\0",key;
cout<<"Please input a string:"<<endl;
cin>>str;
cout<<"please input the key want to delete:"<<endl;
cin>>key;
nLen=strlen(str);
for (i=0;i<=nLen;i++)
{
if (str[i]=='a')
{
for (j=i;j<=nLen;j++)
{
str[i]=str[i+1];
}
nLen--;
}
}
cout<<str<<endl;
}
abcsda-as
please input the key want to delete:
a
bbcsd--ss
Press any key to continue
#include <iostream>
using namespace std;
main()
{
int i,j,nLen;
char str[100]="\0",key;
cout<<"Please input a string:"<<endl;
cin>>str;
cout<<"please input the key want to delete:"<<endl;
cin>>key;
nLen=strlen(str);
for (i=0;i<=nLen;i++)
{
if (str[i]=='a')
{
for (j=i;j<=nLen;j++)
{
str[i]=str[i+1];
}
nLen--;
}
}
cout<<str<<endl;
}
展开全部
Please input a string:
abcsda-as
please input the key want to delete:
a
bbcsd--ss
Press any key to continue
#include <iostream>
using namespace std;
main()
{
int i,j,nLen;
char str[100]="\0",key;
cout<<"Please input a string:"<<endl;
cin>>str;
cout<<"please input the key want to delete:"<<endl;
cin>>key;
nLen=strlen(str);
for (i=0;i<=nLen;i++)
{
if (str[i]=='a')
{
for (j=i;j<=nLen;j++)
{
str[i]=str[i+1];
}
nLen--;
}
}
cout<<str<<endl;
}
abcsda-as
please input the key want to delete:
a
bbcsd--ss
Press any key to continue
#include <iostream>
using namespace std;
main()
{
int i,j,nLen;
char str[100]="\0",key;
cout<<"Please input a string:"<<endl;
cin>>str;
cout<<"please input the key want to delete:"<<endl;
cin>>key;
nLen=strlen(str);
for (i=0;i<=nLen;i++)
{
if (str[i]=='a')
{
for (j=i;j<=nLen;j++)
{
str[i]=str[i+1];
}
nLen--;
}
}
cout<<str<<endl;
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询