zoukankan      html  css  js  c++  java
  • 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 端口转发
    Tomcat笔记
    RocketMQ开启ACL后客户端连接报Algorithm HmacSHA1 not available的解决方式
    RSA签名与验签
    小米9升级MIUI11
    【转】linux awk命令详解
    进程和线程
    Jenkins笔记
    【转】Jenkins启动、停止脚本
    UiAutomator源码分析
  • 原文地址:https://www.cnblogs.com/gallien/p/14387487.html
Copyright © 2011-2022 走看看