solution.cpp 766 字节
Newer Older
每日一练社区's avatar
每日一练社区 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <ctype.h>
static bool isNumber(const char *s)
{
	while (*s == ' ')
		++s;
	bool if_find_num = false;
	if (*s == '-' || *s == '+')
		++s;
	while (isdigit(*s))
	{
		if_find_num = true;
		++s;
	}
	if (*s == '.')
		++s;
	while (isdigit(*s))
	{
		if_find_num = true;
		++s;
	}
	if (if_find_num == true && *s == 'e')
	{
		++s;
		if (*s == '+' || *s == '-')
			++s;
		if_find_num = false;
		while (isdigit(*s))
		{
			if_find_num = true;
			++s;
		}
	}
	while (*s == ' ')
		++s;
	return *s == '\0' && if_find_num == true;
}
int main(int argc, char **argv)
{
	if (argc != 2)
	{
		fprintf(stderr, "Usage: ./test number\n");
		exit(-1);
	}
	printf("%s\n", isNumber(argv[1]) ? "true" : "false");
	return 0;
}