• LL今天心情特别好,因为他去买了一副扑克牌,发现里面居然有2个大王,2个小王(一副牌原本是54张^_^)...他随机从中抽出了5张牌,想测测自己的手气,看看能不能抽到顺子,如果抽到的话,他决定去买体育*,嘿嘿!!“红心A,黑桃3,小王,大王,方片5”,“Oh My God!”不是顺子.....LL不高兴了,他想了想,决定大小 王可以看成任何数字,并且A看作1,J为11,Q为12,K为13。上面


    // test20.cpp : 定义控制台应用程序的入口点。
    //

    #include "stdafx.h"
    #include<iostream>
    #include<vector>
    #include<string>
    #include<queue>
    #include<stack>
    #include<cstring>
    #include<string.h>
    #include<deque>
    
    using namespace std;
    
    
    class Solution {
    	public:
    		bool IsContinuous(vector<int> numbers) {
    			int min = 0, max = 0, count_0 = 0;
    			for (int i = 0;i < numbers.size();++i)
    			{
    				if (numbers[i] == 0)
    				{
    					++count_0;
    					continue;
    				}
    				else
    				{
    					if (min == 0)
    						min = numbers[i];
    					else if (min > numbers[i])
    						min = numbers[i];
    					else {}
    
    					if (max == 0)
    						max = numbers[i];
    					else if (max < numbers[i])
    						max = numbers[i];
    					else{}
    					
    				}
    			}
    			if (count_0 == 4) return true;
    			if (max == min) return false;
    			if (max - min>4) return false;
    			return true;
    			
    		}
    	};
    int main()
    {
    	
    	Solution so;
    	vector<int> numbers = { 1,2,3,4,5 };
     /*   bool result=so.IsContinuous(numbers);
    	cout <<"result:"<< result << endl;*/
    
    	bool result = so.IsContinuous(numbers);
    	cout << "result:" << result << endl;
    
    	cout << endl;
    	return 0;
    }
    
    // test20.cpp : 定义控制台应用程序的入口点。
    //
    
    #include "stdafx.h"
    #include<iostream>
    #include<vector>
    #include<string>
    #include<queue>
    #include<stack>
    #include<cstring>
    #include<string.h>
    #include<deque>
    
    using namespace std;
    
    
    class Solution {
    	public:
    		bool IsContinuous(vector<int> numbers) {
    			int min = 0, max = 0, count_0 = 0;
    			for (int i = 0;i < numbers.size();++i)
    			{
    				if (numbers[i] == 0)
    				{
    					++count_0;
    					continue;
    				}
    				else
    				{
    					if (min == 0)
    						min = numbers[i];
    					else if (min > numbers[i])
    						min = numbers[i];
    					else {}
    
    					if (max == 0)
    						max = numbers[i];
    					else if (max < numbers[i])
    						max = numbers[i];
    					else{}
    					
    				}
    			}
    			if (count_0 == 4) return true;
    			if (max == min) return false;
    			if (max - min>4) return false;
    			return true;
    			
    		}
    	};
    int main()
    {
    	
    	Solution so;
    	vector<int> numbers = { 1,2,3,4,5 };
     /*   bool result=so.IsContinuous(numbers);
    	cout <<"result:"<< result << endl;*/
    
    	bool result = so.IsContinuous(numbers);
    	cout << "result:" << result << endl;
    
    	cout << endl;
    	return 0;
    }
  • 相关阅读:
    slf4j日志框架绑定机制
    Btrace使用入门
    JVM反调调用优化,导致发生大量异常时log4j2线程阻塞
    [转载]Javassist 使用指南(三)
    [转载]Javassist 使用指南(二)
    [转载]Javassist 使用指南(一)
    数组升序排序的方法Arrays.sort();的应用
    copyOfRange的应用
    copyOf数组复制方法的使用(数组扩容练习)
    binarySearch(int[] a,int fromIndex,int toIndex, int key)的用法
  • 原文地址:https://www.cnblogs.com/wdan2016/p/6029759.html
Copyright © 2020-2023  润新知