我现在正在训练鳕鱼.我可以自己解决一些任务,但有些任务有问题.这项任务的难度是<**>.这是中等的,但我停滞不前.
问题:
您将获得一个由N个整数组成的非空零索引数组A. 对于每个数字A [i],使得0≤i<N,我们想要计算不是A [i]的除数的数组的元素的数量.我们说这些元素是非除数.例如,考虑整数N = 5和数组A,以便:
A[0] = 3
A[1] = 1
A[2] = 2
A[3] = 3
A[4] = 6
Run Code Online (Sandbox Code Playgroud)
对于以下元素:
A[0] = 3, the non-divisors are: 2, 6,
A[1] = 1, the non-divisors are: 3, 2, 3, 6,
A[2] = 2, the non-divisors are: 3, 3, 6,
A[3] = 3, the non-divisors are: 2, 6,
A[6] = 6, there aren't any non-divisors.
Run Code Online (Sandbox Code Playgroud)
写一个函数:
class Solution { public int[] solution(int[] A); }
Run Code Online (Sandbox Code Playgroud)
在给定由N个整数组成的非空零索引数组A的情况下,返回表示非除数的数的整数序列.序列应返回为:
我有DataGridViewComboBoxCell和DataTable.表I中的数据使用DataSource与DataGridViewComboBoxCell绑定,并设置ValueMember和DisplayMember.
private void Form1_Load(object sender, EventArgs e)
{
DataGridViewComboBoxCell comboBoxCell = new DataGridViewComboBoxCell();
dataGridView1.Rows[0].Cells[0] = comboBoxCell;
comboBoxCell.DataSource = dataTable;
comboBoxCell.ValueMember = "ID";
comboBoxCell.DisplayMember = "Item";
}
Run Code Online (Sandbox Code Playgroud)
如何在表单加载时以编程方式设置单元格中的值?在简单的ComboBox中,我知道一个属性SelectedIndex.我试过comboBoxCell.Value = ...; 但它给了一个例外.并尝试过
private void dataGridView1_CellFormatting(object sender,
DataGridViewCellFormattingEventArgs e)
{
e.Value = 1;
}
Run Code Online (Sandbox Code Playgroud)
它在单元格中设置了一个新值,但我需要选择一个值.
表单已加载,我有空单元格.

还有ComboBox中的一些数据.

当我把这个代码放在dataGridView1.Rows[0].Cells["ComboColumn"].Value = "1";comboBoxCell.DisplayMember = ...之后(见上文)时,它运行正常.
ID列中的值"1"对应于Items列中的值"Second".因此,我得到了正确的结果.

抱歉我的英文和我的新手代码:)
我有DataGridView.在某些单元格中,我添加了一些数据 如果我正在编辑的单元格是空的并且我即将离开它,则向用户显示消息"bla-bla-bla",并且处于编辑模式的单元必须接收焦点.
这样做的我用CellEnter,CellLeave,CellEndEdit等我想检查单元格中输入值后取消的事件.但我不是,它不起作用.请帮我.很高兴看到任何建议.
这是我的代码的变体.我试过其他事件,但这很天真.
private void dataGridView1_CellEndEdit(object sender, DataGridViewCellEventArgs e)
{
if (dataGridView1[e.ColumnIndex, e.RowIndex] == null)
{
MessageBox.Show("Empty cell!");
dataGridView1.CurrentCell = dataGridView1[e.ColumnIndex, e.RowIndex];
}
}
Run Code Online (Sandbox Code Playgroud)