列表

详情


NC214663. Luckynumbers

描述

    The sum of the three three-digit numbers is 999 and each of their digits is not repeated,
and cannot have 0, then these three numbers are called: a group of lucky numbers.

输入描述

no input

输出描述

Output the lucky numbers of all groups, the three numbers in each group are sorted from small to large, and between groups are sorted by the first number from small to large. If the first number is the same, the second number is sorted from small to large.If the second number is also the same, sorted by the third number from small to large

原站题解

上次编辑到这里,代码来自缓存 点击恢复默认模板

C++(clang++11) 解法, 执行用时: 5ms, 内存消耗: 376K, 提交时间: 2021-01-22 21:02:52

#include<bits/stdc++.h>
using namespace std;
int a[9]={1,2,3,4,5,6,7,8,9};
int main()
{
	int x,y,z;
	while(next_permutation(a,a+9))
	{
		x=a[0]*100+a[1]*10+a[2];
		y=a[3]*100+a[4]*10+a[5];
		z=a[6]*100+a[7]*10+a[8];
		if(x+y+z==999&&x<y&&y<z)
		printf("%d %d %d\n",x,y,z);
	}
	return 0;
}

Python3 解法, 执行用时: 627ms, 内存消耗: 4656K, 提交时间: 2022-01-01 17:45:29

import itertools
for i in itertools.permutations(map(str,range(1,10)),9):
    r,s,t=map(lambda x:int(''.join(x)),[i[:3],i[3:6],i[6:]])
    if r+s+t==999 and r<s<t:print(r,s,t)

上一题