• leetcode-剑指20-OK


    // language C with STL(C++)
    // 剑指20
    // https://leetcode-cn.com/problems/biao-shi-shu-zhi-de-zi-fu-chuan-lcof/
    // 好恶心的题
    
    class Solution {
    public:
    	bool isAnum(char a){
    		if(a == '0')
    			return true;
    		if(a == '1')
    			return true;
    		if(a == '2')
    			return true;
    		if(a == '3')
    			return true;
    		if(a == '4')
    			return true;
    		if(a == '5')
    			return true;
    		if(a == '6')
    			return true;
    		if(a == '7')
    			return true;
    		if(a == '8')
    			return true;
    		if(a == '9')
    			return true;
    		return false;
    	}
    
    
        bool isNumber(string s) {	// 有e有点,有e无点,无e有点,无e无点
        	int firstnotspace = 0;
        	int len = s.length();
        	while(s[firstnotspace] ==' ' && firstnotspace<len-1){
        		firstnotspace++;
        	}
        	int lastnotspace = len-1;
            // printf("%d-", lastnotspace);
        	while(s[lastnotspace] ==' '&& lastnotspace>0)
        		lastnotspace --;
        	if(s[lastnotspace] ==' ')
        		return false;
        	len = len-(firstnotspace)-(len-1-lastnotspace);
            // printf("%d-", firstnotspace);
            // printf("%d-", lastnotspace);
        	if(len <=0)
        		return false;
        	bool eflag=false;
        	bool pointflag = false;
        	bool numflag = false;
        	for(int i = firstnotspace; i<= lastnotspace; i++){
        		if(isAnum(s[i])){
        			numflag =true;
        		}else if((s[i] =='e') ||(s[i] =='E')){
        			if(numflag && !eflag){
        				eflag = true;
        				numflag = false;
        			}else{
        				// printf("%d-", i);
        				return false;
        			}
        		}else if(s[i] == '.'){
        			if(eflag||pointflag){
        				// printf("%d-", i);
        				return false;
        			}else{
        				pointflag = true;
        			}
        		}else if(((s[i] == '+')||(s[i] == '-')) &&( (i ==firstnotspace)|| (s[i-1] =='e')||(s[i-1] =='E'))){
    
        		}else{
        			// printf("%d-", i);
        			return false;
        		}
        	}
        	return numflag;
        }
    };
    
  • 相关阅读:
    JAVA中==与equals的区别
    spring面试重点
    struts2
    每个新手程序员必看的 SQL 指南
    QueryRunner的使用
    jquery GET POST
    jquery添加元素
    jquery 滑动动画
    jdbc 安装驱动
    为什么做java的web开发我们会使用struts2,springMVC和spring这样的框架?
  • 原文地址:https://www.cnblogs.com/gallien/p/14387487.html
Copyright © 2020-2023  润新知