View Code of Problem 50

#include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<algorithm>
#include<ctype.h>
#include<string.h>
#include<math.h>
#include<queue>
#include<string>

using namespace std;
const int maxn = 1000 + 5;
char a[maxn];
int num = 0;
int flag = 1;
int main()
{
	int i = 0;
	char str[maxn];
	gets(str);
	for(int i=0;i<strlen(str);i++)
	{
		//如果扫描到数字
		//1.判断前方是否为非数字字符 如果是 那么打印 * 打印这个数字
		//如果前方还是数字 打印该数字 移动1
		if (isdigit(str[i]))
		{
			a[num++] = str[i];
			flag = 1;

		}
		else 
		{
			if(flag==1)
			a[num++] = '*';
			flag = 0;
		}
	}
	cout << a;

}

Double click to view unformatted code.


Back to problem 50