输入:字符串
输出:数字前后加*
如:
输入:sfadf5678sdfm12w3o
输出:sfadf*5678*sdfm*12*w*3*
#include <iostream>
using namespace std;
int main()
{
char str[100];
gets_s(str);
if (str[0] >= '0'&&str[0] <= '9')
{
cout << '*' << str[0];
}
else
cout << str[0];
for (int i = 1;i < strlen(str);i++)
{
if ((str[i] >= '0'&&str[i] <= '9')&&(str[i-1] <'0'||str[i-1] > '9')&& (str[i+1] < '0'||str[i+1] > '9'))
{
cout << "*" << str[i] << "*";
}
else if((str[i] >= '0'&&str[i] <= '9')&& (str[i-1] >= '0'&&str[i-1] <= '9')&& (str[i+1] < '0'||str[i+1] >'9'))
{
cout << str[i]<<"*";
}
else if ((str[i] >= '0'&&str[i] <= '9') && (str[i + 1] >='0'&&str[i +1] <= '9') && (str[i-1] < '0' || str[i - 1] >'9'))
{
cout << '*' << str[i];
}
else
{
cout << str[i];
}
}
return 0;
}
o