字符串组合和最小公倍数和最大公约数问题
//例如输入字符串abc,则输出由字符a、b、c 所能排列出来的所有字符串
public static void AllArray(string str, string str2 = "")
{
if (str == null)
return;
if (str == string.Empty)
Console.WriteLine(str2);
for (int i = 0; i < str.Length; i++)
{
AllArray(str.Remove(i, 1), str2 + str[i].ToString());
}
}
public static void MinGong()
{
int temp1 = int.Parse(Console.ReadLine());
int temp2 = int.Parse(Console.ReadLine());
int n1 = Math.Max(temp1, temp2);
int n2 = Math.Min(temp1, temp2);
int Mul = n1 * n2;
int min;
int m;
//最大公约数
while (n2 != 0)
{
n1 = n1 > n2 ? n1 : n2;
m = n1 % n2;
n1 = n2;
n2 = m;
}
min = Mul / n1;
Console.WriteLine(n1);
Console.WriteLine(min);
}
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】博客园社区专享云产品让利特惠,阿里云新客6.5折上折
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步