uva 441 Lotto

本文介绍了一种通过暴力求解的方式找到所有可能的六数组合的算法实现。该方法适用于输入一系列递增数字并从中选取六个数字的所有组合情况。通过多重循环遍历实现了对输入数字的组合生成。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

题目:输入一个n,然后输入n个数字(递增且n>6),然后取其中的6个数字

方法:看到同学的方法才明白了可以用暴力求解,虽然循环比较多,但是好理解

注意:空行

#include<iostream>  
#include<cstdio>  
#include<cstring>  
#include<cstdlib>  
#include<cctype>  
#include<algorithm>  
using namespace std;
int main(int argc, char *argv[]) {
	int num[100],a,b,c,d,e,f,n;
	int flag=0;//用来控制行之间回车
	
	while (cin >> n) {
		if(flag!=0 && n!=0) cout<<endl;
		if(n==0)break;
		for(int i = 0; i < n; i++) cin >> num[i];
		for(a = 0; a < n-5; a++){
			for(b = a+1; b < n-4; b++){
				for(c = b+1; c < n-3; c++){
					for(d = c+1; d < n-2; d++){
						for(e = d+1; e < n-1; e++){
							for(f = e+1; f < n; f++){
								cout << num[a]<<" " << num[b]<<" " << num[c]<<" " << num[d]<<" " << num[e]<<" " << num[f] << endl;
							}
						}
					}
				}
			}
		}
		flag++;
	//cout<<endl;
	}
	return 0;
	
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值