zoukankan      html  css  js  c++  java
  • 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;
    }
  • 相关阅读:
    Linux IO接口 监控 (iostat)
    linux 防火墙 命令
    _CommandPtr 添加参数 0xC0000005: Access violation writing location 0xcccccccc 错误
    Visual Studio自动关闭
    Linux vsftpd 安装 配置
    linux 挂载外部存储设备 (mount)
    myeclipse 9.0 激活 for win7 redhat mac 亲测
    英文操作系统 Myeclipse Console 乱码问题
    Linux 基本操作命令
    linux 查看系统相关 命令
  • 原文地址:https://www.cnblogs.com/wdan2016/p/6029759.html
Copyright © 2011-2022 走看看