算法求解，控制台

``````
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace NumMax
{
class Program
{
static void Main(string[] args)
{
float[] arrFirst = { 3, 2, 6, 4, 1, 9 };
float[] arrSecond = { 7, 14, 7, 12, 5, 22 };
float[] arrThird = new float[arrFirst.Length];
float[] arrForth = new float[arrFirst.Length];
//float temp = 0;
float max = arrThird[0];
int index = 0;
for (int x = 0; x < arrFirst[index]; x++)
{
for (int i = 0; i < arrFirst.Length; i++)
{
arrThird[i] = arrFirst[i] / arrSecond[i];
}
for (int j = 0; j < arrThird.Length; j++)
{
if (arrThird[j] > arrThird[index])
{
index = j;
max = arrThird[j];
arrForth[j] = max;
}
if (arrForth[j] == 0)
{
return;
}
else
{
Console.WriteLine(arrForth[j]);
}
}
arrFirst[index] -= 1;
}
}
}
}

``````
...全文
169 4 点赞 打赏 收藏 举报

4 条回复

linq的用法 float[] arrFirst = { 3, 2, 6, 4, 1, 9 }; float[] arrSecond = { 7, 14, 7, 12, 5, 22 }; float[] arrThird = arrFirst.Select((x, i) => x / arrSecond[i])……

• 打赏
• 举报

gxingmin 2013-02-20
linq的用法 float[] arrFirst = { 3, 2, 6, 4, 1, 9 }; float[] arrSecond = { 7, 14, 7, 12, 5, 22 }; float[] arrThird = arrFirst.Select((x, i) => x / arrSecond[i]).ToArray<float>(); //数组1和数组2对应的相除得第3个数组 var max = arrThird.Max(); //取第三个数组最大的值 var index = Array.IndexOf(arrThird, max); //去最大值对应的位置索引 Console.WriteLine(max); //输出这个最大值 Console.Read(); if(index>-1) //其实这个判断可以去掉，肯定会大于-1的 arrFirst[index]--; //将最大值对应位置的第一个数组自减1
• 打赏
• 举报

C# code?123456789101112 float[] arrFirst = { 3, 2, 6, 4, 1, 9 }; float[] arrSecond = { 7, 14, 7, 12, 5, 22 }; float[] arrThird = arrFirst.Select((x, i) => x / arrS……

• 打赏
• 举报

gxingmin 2013-02-20
``````  float[] arrFirst = { 3, 2, 6, 4, 1, 9 };
float[] arrSecond = { 7, 14, 7, 12, 5, 22 };

float[] arrThird = arrFirst.Select((x, i) => x / arrSecond[i]).ToArray<float>();
var max = arrThird.Max();
var index = Array.IndexOf(arrThird, max);

Console.WriteLine(max);

if(index>-1)
arrFirst[index]--;``````
• 打赏
• 举报

C#

10.6w+

.NET技术 C#

2013-02-20 04:52