// test20.cpp : 定义控制台应用程序的入口点。
//
#include "stdafx.h"
#include<iostream>
#include<vector>
#include<string>
#include<queue>
#include<stack>
#include<cstring>
#include<string.h>
#include<deque>
#include <forward_list>
using namespace std;
class Solution {
public:
bool isNumeric(char* str)
{
string s = str;
//如果存在不合法字符
if (s.find_first_of("eE") > s.size())
{
if (s.find_first_of("+-") > 0&&s.find_first_of("+-")<s.size())
return false;
}
if (s.find_first_of("abcdfghijklmnopqrstuvwxyz") < s.size())
return false;
if (s.find_first_of("e") == s.size() - 1)
return false;
//不存在e,但是有两个正号或者符号
//找到了E,但是eE后面有.
if(s.find_first_of(".")<s.size())
if (s.find_first_of("eE") < s.find_first_of("."))
return false;
int first = s.find_first_of("+-");
int last = s.find_last_of("+-");
if (s.find_first_of("eE")>s.size()&&first != last) return false;
int first1 = s.find_first_of(".");
int last1 = s.find_last_of(".");
if ( first1 != last1) return false;
// cout << s << endl;
return true;
}
};
int main()
{
Solution so;
// vector<int> numbers = { 1,2,3,4,5 };
/* bool result=so.IsContinuous(numbers);
cout <<"result:"<< result << endl;*/
char* str = "1.79769313486232E+308";
bool result = so.isNumeric(str);
cout << "result:" << result << endl;
cout << endl;
return 0;
}
注意:这个用到了正则表达式!!!!!!!!!!
我的这个方法不好!!!!!!!!
要熟悉正则表达式!!!!!!