排列(permutation)
来源:互联网 发布:caffe 安装cudnn 编辑:程序博客网 时间:2024/06/14 11:24
用1,2,3,…,9组成3个三位数abc,def和ghi,每个数字恰好使用一次,要 求abc:def:ghi=1:2:3。按照“abc def ghi”的格式输出所有解,每行一个解。提示:不必 太动脑筋。
#include <stdio.h>
void result(int num, int &result_add, int &result_mul)
{
int i, j, k;
i = num / 100; //百位
j = num / 10 % 10; //十位
k = num % 10; //个位
result_add += i + j + k; //分解出来的位数相加
result_mul *= i * j * k; //相乘
}
void result(int num, int &result_add, int &result_mul)
{
int i, j, k;
i = num / 100; //百位
j = num / 10 % 10; //十位
k = num % 10; //个位
result_add += i + j + k; //分解出来的位数相加
result_mul *= i * j * k; //相乘
}
int main()
{
int i, j, k;
int result_add, result_mul;
for(i = 123; i <=329; i++)
{
j = i * 2;
k = i * 3;
result_add = 0;
result_mul = 1;
result(i, result_add, result_mul);
result(j, result_add, result_mul);
result(k, result_add, result_mul);
if(result_add == 45 && result_mul == 362880)
{
printf("%d %d %d\n", i, j, k);
}
}
return 0;
}
{
int i, j, k;
int result_add, result_mul;
for(i = 123; i <=329; i++)
{
j = i * 2;
k = i * 3;
result_add = 0;
result_mul = 1;
result(i, result_add, result_mul);
result(j, result_add, result_mul);
result(k, result_add, result_mul);
if(result_add == 45 && result_mul == 362880)
{
printf("%d %d %d\n", i, j, k);
}
}
return 0;
}
阅读全文
0 0
- 排列(permutation)
- 排列(permutation)
- 排列问题(permutation)
- 排列(permutation)
- 回文排列(Palindrome Permutation)
- leetcode-全排列(permutation)
- 排列(Permutation)
- 习题 2-10 排列(permutation)
- UVa 11027 - Palindromic Permutation(排列编码)
- LeetCode | Next Permutation(下一个排列)
- LeetCode 31 Next Permutation(下一个排列)
- 习题2-6 排列(permutation)
- LeetCode 266. Palindrome Permutation(对称排列)
- LeetCode 31. Next Permutation(下一个排列)
- LeetCode 60. Permutation Sequence(排列序列)
- LeetCode 31 Next Permutation (下一个排列)
- 31. Next Permutation (下一个排列)
- 习题2-6 排列(permutation)
- 【OpenCV入门指南】第七篇 线段检测与圆检测
- String的注意事项
- TensorFlow学习笔记(一)
- Android N编译之Out of memory error
- 声明式编程和命令式编程的比较
- 排列(permutation)
- 【OpenCV入门指南】第八篇 灰度直方图
- (java)String 中 ==与equals方法 的区别
- 纯CSS实现多页签跳转
- Git相关知识(2)
- 插入排序算法(C实现)
- jQuery
- 【OpenCV入门指南】第九篇 灰度直方图均衡化
- sharesdk分享问题