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;
        }
    };
    
  • 相关阅读:
    redmine工作流程总结
    IOS_OC_Category
    权限问题导致无法删除ftp文件
    Window下UDP(socket)接和收数据案例
    新一批创业者入局 谁来挖掘其身上的金矿
    java代理使用 apache ant实现文件压缩/解压缩
    ZOJ Monthly, November 2012
    【cocos2d-x 3.7 飞机大战】 决战南海I (十) 游戏主场景
    getAttribute for IE7
    Sahara中的数据模型
  • 原文地址:https://www.cnblogs.com/gallien/p/14387487.html
Copyright © 2011-2022 走看看