大佬们帮忙看看这道编程题题为什么输出不对,本人菜鸟一枚
- 题目:字符中所有出现的数字前后加上符号“*”,其他字符保持不变
- 没弄明白最后多输出的部分是怎么回事,在自己编译器上是正确输出,求解答。
- 测试用例:5O6t6FFtIlMVDn7rTaZki4Pl42Xx6n正确输出:*5*O*6*t*6*FFtIlMVDn*7*rTaZki*4*Pl*42*Xx*6*n我的输出:*5*O*6*t*6*FFtIlMVDn*7*rTaZki*4*Pl*42*Xx*6*n*2211*KpU*0*o*7*nZbj
- #include <stdio.h>
- #include <string.h>
- #include <ctype.h>
- int main(void)
- {
- char s[1000]={0};
- int i;
- while (gets(s))
- {
- char * pBegin,* pEnd;
- pBegin = pEnd = s;
- while (*pBegin)
- {
- if ( !isdigit(*pBegin) )
- {
- printf("%c",*pBegin);
- pBegin++;
- pEnd++;
- }
- else if (!isdigit(*pEnd)||*pEnd == '\0')
- {
- printf("*");
- while (pBegin<pEnd)
- {
- printf("%c",*pBegin);
- pBegin++;
- }
- printf("*");
- pBegin = pEnd;
- }
- else
- pEnd++;
- }
- }
- return 0;
- }