c++ 送分
来源:百度知道 编辑:UC知道 时间:2024/06/17 23:13:20
Description
输入一个字符串str1,把其中的连续非数字的字符子串换成一个‘*’,存入字符数组str2 中,所有数字字符也必须依次存入 str2 中。输出str2。
Input
输入为一行字符串str1,其中可能包含空格。字符串长度不超过80个字符。
Output
输出处理好的字符串str2。
Sample Input
$Ts!47&*s456 a23* +B9k
Sample Output
*47*456*23*9*
输入一个字符串str1,把其中的连续非数字的字符子串换成一个‘*’,存入字符数组str2 中,所有数字字符也必须依次存入 str2 中。输出str2。
Input
输入为一行字符串str1,其中可能包含空格。字符串长度不超过80个字符。
Output
输出处理好的字符串str2。
Sample Input
$Ts!47&*s456 a23* +B9k
Sample Output
*47*456*23*9*
#include <iostream>
using namespace std;
#define MAXSIZE 80
int main()
{
char str1[MAXSIZE+1];
char str2[MAXSIZE+1];
cin.getline(str1, MAXSIZE);
int i, j=0, len=strlen(str1);
bool pn=true;
for(i=0; i<len; i++)
{
if(str1[i]>='0' && str1[i]<='9')
{
pn=true;
str2[j++]=str1[i];
}
else
if(pn)
{
str2[j++]='*';
pn=false;
}
}
str2[j]='\0';
cout<<str2;
return(0);
}
#include <iostream>
using namespace std;
const int s = 80;
void myreplace(){
char s1[s];
char s2[s];
int i = 0,j = 0;
cin>>s1;
bool isother = false;
for(;i<s;i++){
if(s1[i]>='0'&&s1[i]<='9'){
if(isother){
s2[j]='*';
++j;
}
s