题目描述
将一个字符中所有的整数前后加上符号“*”,其他字符保持不变。连续的数字视为一个整数。
注意:本题有多组样例输入。
数据范围:字符串长度满足 【1,100】
输入描述:
输入一个字符串
输出描述:
字符中所有出现的数字前后加上符号“*”,其他字符保持不变
示例1
输入:
Jkdi234klowe90a3
5151
输出:
Jkdi234klowe90a3
5151
题解思路
- 如果遇到数字,则数字前后加 *
代码实现
#include <stdio.h>
#include <string.h>
int main()
{
char str[101] = {0};
char result[202] = {0};
int i, j;
while(gets(str) != NULL) {
i = 0;
j = 0;
memset(result, 0, 202);
while(str[i] != '\0') {
if(isdigit(str[i])) {
result[j++] = '*';
result[j++] = str[i++];
while(isdigit(str[i])) {
result[j++] = str[i++];
}
result[j++] = '*';
}
else {
result[j++] = str[i++];
}
}
puts(result);
}
return 0;
}
371

被折叠的 条评论
为什么被折叠?



