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_s(str);
	for(int i=1;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;

}
/*
Main.cc: In function 'int main()':
Main.cc:19:12: error: 'gets_s' was not declared in this scope
  gets_s(str);
            ^
Main.cc:20:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i=1;i<strlen(str);i++)
               ^
Main.cc:17:6: warning: unused variable 'i' [-Wunused-variable]
  int i = 0;
      ^
*/

Double click to view unformatted code.


Back to problem 50