用C#语言将1,2,3...9九位数分成三组,组成3个三位数且满足1:2:3的比例,
来源:学生作业帮 编辑:作业帮 分类:综合作业 时间:2024/07/20 05:15:48
用C#语言将1,2,3...9九位数分成三组,组成3个三位数且满足1:2:3的比例,
之前回答过同样的问题.这个就是给这道题写的using System;
using System.Collections.Generic;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
List<int> _L1 = new List<int>();
int x = 0, y = 0, z = 0;
for (int i = 1; i < 10; i++) _L1.Add(i);
foreach (int a in _L1)
{
List<int> _L2 = new List<int>(_L1);
_L2.Remove(a);
foreach (int b in _L2)
{
List<int> _L3 = new List<int>(_L2);
_L3.Remove(b);
foreach (int c in _L3)
{
x = a * 100 + b * 10 + c;
List<int> _L4 = new List<int>(_L3);
_L4.Remove(c);
foreach (int d in _L4)
{
List<int> _L5 = new List<int>(_L4);
_L5.Remove(d);
foreach (int e in _L5)
{
List<int> _L6 = new List<int>(_L5);
_L6.Remove(e);
foreach (int f in _L6)
{
y = d * 100 + e * 10 + f;
List<int> _L7 = new List<int>(_L6);
_L7.Remove(f);
foreach (int g in _L7)
{
List<int> _L8 = new List<int>(_L7);
_L8.Remove(g);
foreach(int h in _L8)
{
List<int> _L9 = new List<int>(_L8);
_L9.Remove(h);
z = g * 100 + h * 10 + _L9[0];
if (y == x * 2 && z == x * 3)
Console.WriteLine(x + "," + y + "," + z);
}
}
}
}
}
}
}
}
Console.ReadKey();
}
}
}下面这个用到了强制代码,你自己取舍,两个都可以实现,第一个基本逻辑思路,第二个简化算法,节省时间
using System;
using System.Collections.Generic;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
List<int> _L1 = new List<int>();
for (int i = 1; i < 10; i++) _L1.Add(i);
foreach (int x in _L1)
{
List<int> _L2 = new List<int>(_L1);
_L2.Remove(x);
foreach (int y in _L2)
{
List<int> _L3 = new List<int>(_L2);
_L3.Remove(y);
foreach (int z in _L3)
{
int i = x * 100 + y * 10 + z;
int ii = i * 2;
char[] cii = ii.ToString().ToCharArray();
if (cii[0] == cii[1] || cii[0] == cii[2] || cii[1] == cii[2]) continue;
List<int> _L4 = new List<int>(_L3);
_L4.Remove(z);
foreach (char c in cii)
{
if (!_L4.Contains(int.Parse(c.ToString())))goto H1;
}
int iii = i * 3;
char[] ciii=iii.ToString().ToCharArray();
if (ciii[0] == ciii[1] || ciii[0] == cii[2] || ciii[1] == ciii[2]) continue;
List<int> _L5 = new List<int>(_L4);
foreach (char c in cii) _L5.Remove(int.Parse(c.ToString()));
foreach (char c in ciii)
{
if (!_L5.Contains(int.Parse(c.ToString())))
goto H1;
}
Console.WriteLine(i + "," + ii + "," + iii);
H1: ;
}
}
}
Console.ReadKey();
}
}
}
using System.Collections.Generic;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
List<int> _L1 = new List<int>();
int x = 0, y = 0, z = 0;
for (int i = 1; i < 10; i++) _L1.Add(i);
foreach (int a in _L1)
{
List<int> _L2 = new List<int>(_L1);
_L2.Remove(a);
foreach (int b in _L2)
{
List<int> _L3 = new List<int>(_L2);
_L3.Remove(b);
foreach (int c in _L3)
{
x = a * 100 + b * 10 + c;
List<int> _L4 = new List<int>(_L3);
_L4.Remove(c);
foreach (int d in _L4)
{
List<int> _L5 = new List<int>(_L4);
_L5.Remove(d);
foreach (int e in _L5)
{
List<int> _L6 = new List<int>(_L5);
_L6.Remove(e);
foreach (int f in _L6)
{
y = d * 100 + e * 10 + f;
List<int> _L7 = new List<int>(_L6);
_L7.Remove(f);
foreach (int g in _L7)
{
List<int> _L8 = new List<int>(_L7);
_L8.Remove(g);
foreach(int h in _L8)
{
List<int> _L9 = new List<int>(_L8);
_L9.Remove(h);
z = g * 100 + h * 10 + _L9[0];
if (y == x * 2 && z == x * 3)
Console.WriteLine(x + "," + y + "," + z);
}
}
}
}
}
}
}
}
Console.ReadKey();
}
}
}下面这个用到了强制代码,你自己取舍,两个都可以实现,第一个基本逻辑思路,第二个简化算法,节省时间
using System;
using System.Collections.Generic;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
List<int> _L1 = new List<int>();
for (int i = 1; i < 10; i++) _L1.Add(i);
foreach (int x in _L1)
{
List<int> _L2 = new List<int>(_L1);
_L2.Remove(x);
foreach (int y in _L2)
{
List<int> _L3 = new List<int>(_L2);
_L3.Remove(y);
foreach (int z in _L3)
{
int i = x * 100 + y * 10 + z;
int ii = i * 2;
char[] cii = ii.ToString().ToCharArray();
if (cii[0] == cii[1] || cii[0] == cii[2] || cii[1] == cii[2]) continue;
List<int> _L4 = new List<int>(_L3);
_L4.Remove(z);
foreach (char c in cii)
{
if (!_L4.Contains(int.Parse(c.ToString())))goto H1;
}
int iii = i * 3;
char[] ciii=iii.ToString().ToCharArray();
if (ciii[0] == ciii[1] || ciii[0] == cii[2] || ciii[1] == ciii[2]) continue;
List<int> _L5 = new List<int>(_L4);
foreach (char c in cii) _L5.Remove(int.Parse(c.ToString()));
foreach (char c in ciii)
{
if (!_L5.Contains(int.Parse(c.ToString())))
goto H1;
}
Console.WriteLine(i + "," + ii + "," + iii);
H1: ;
}
}
}
Console.ReadKey();
}
}
}
用pascal语言将1,2,…,9共9 个数分成3组,分别组成3个3位数,且使这3个3位数构成1:2:3的比例,试求出所
将1~9这9个数字分成三组(每个数字只能用一次),分别组成三位数,且这三个三位数的值构成1:2:3的比例.
pascal 巧妙填数 将1,2,…,9共9个数分成三组,分别组成三个三位数,且使这三个三位数构成 1:2:3的比例
将1-9这9个数子分成三组(每个数字只能使用一次),分别组成三个三位数,值构成1:2:3的比例
将1-9共9个数字分成三组,分别组成3个三位数,使这三个三位数构成1:2:3
将1到9九个数字分成三组,组成三位数,使它们之间的比例依次是1:3:5,怎样分组?
把1~9的自然数分为三组,组成数字互不重复的3个3位数,且这些3位数之比为1:2:3,问满足条件的所有3位数
C#实现有1、2、3、4个数字,能组成多少个互不相同且无重复数字的三位数?都是些什么组合
将1,2,3,4,5,6,7这七个数分成两组,组成一个三位数和一个四位数,并使这两个数的乘积最大,那么这个三位数是___
用C语言写程序:有1、2、3、4个数字,能组成多少个互不相同且无重复数字的三位数?都是多少?
用C语言编程 1、有1、2、3、4个数字,能组成多少个互不相同且无重复数字的四位数?都是多少? 2
用C语言编写有1,2,3,4四个数,能组成多少个互不相同且无重复数字的三位数,都是多少