gpt-4-0314· openai
WildChat-4.8M
You are a programmer. Make the code below unique, it was taken from the Internet. It is…
- User
You are a programmer. Make the code below unique, it was taken from the Internet. It is written in C# Sharp. Leave the names of the buttons and events as in the original version (button1_click, button2_click, button3_click, button4_click, textbox1, textbox2, listbox1). Keep the code short, if possible.
namespace ii3 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } List<string[]> objs;
private void button1_Click(object sender, EventArgs e) { if (textBox1.Text != "" && textBox2.Text != "" && textBox3.Text != "" && listBox1.FindString(textBox1.Text) == -1) { listBox1.Items.Add(textBox1.Text); objs.Add(new string[3] { textBox1.Text, textBox2.Text, textBox3.Text }); textBox1.Text = textBox2.Text = textBox3.Text = ""; } } private void Form1_Load(object sender, EventArgs e) { button2.Enabled = false; button3.Enabled = false; objs = new List<string[]>(); openFile(); } private void saveToFile() { StreamWriter w = new StreamWriter("data"); for (int i = 0; i < objs.Count; i++) w.WriteLine(objs[i][0] + ";" + objs[i][1] + ";" + objs[i][2]); w.Close(); } private void openFile() { try { String s; objs.Clear(); listBox1.Items.Clear(); StreamReader r = new StreamReader("data"); while ((s = r.ReadLine()) != null) { objs.Add(new string[3] { s.Split(';')[0], s.Split(';')[1], s.Split(';')[2] }); listBox1.Items.Add(s.Split(';')[0]); } r.Close(); } catch { } } private void listBox1_SelectedIndexChanged(object sender, EventArgs e) { if (listBox1.SelectedIndex == -1) return; String[] o = objs[listBox1.SelectedIndex]; textBox1.Text = o[0]; textBox2.Text = o[1]; textBox3.Text = o[2]; button1.Enabled = false; button2.Enabled = true; button3.Enabled = true; } private void button2_Click(object sender, EventArgs e) { int i = listBox1.SelectedIndex; if (textBox1.Text != "" && textBox2.Text != "" && textBox3.Text != "") { objs[i][0] = textBox1.Text; objs[i][1] = textBox2.Text; objs[i][2] = textBox3.Text; listBox1.Items[listBox1.SelectedIndex] = textBox1.Text; textBox1.Text = textBox2.Text = textBox3.Text = ""; button1.Enabled = true; button2.Enabled = false; button3.Enabled = false; listBox1.ClearSelected(); } } private void button3_Click(object sender, EventArgs e) { int i = listBox1.SelectedIndex; objs.RemoveAt(i); listBox1.Items.RemoveAt(i); textBox1.Text = textBox2.Text = textBox3.Text = ""; button1.Enabled = true; button2.Enabled = false; button3.Enabled = false; listBox1.ClearSelected(); } private void Form1_FormClosing(object sender, FormClosingEventArgs e) { saveToFile(); } private void button4_Click(object sender, EventArgs e) { String[] qs = new String[objs.Count * 2]; for (int i = 0; i < objs.Count; i++) { qs[i * 2] = objs[i][1]; qs[i * 2 + 1] = objs[i][2]; } int[] ans = { -1, -1 }; int pcount = 0; var r = new Random(); qs = qs.OrderBy(x => r.Next()).ToArray(); for (int i = 0; i < objs.Count * 2 && pcount != 2; i++) { if (MessageBox.Show("Объект " + qs[i] + "?", "Вопрос " + (i + 1), MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { ans[pcount++] = i; } } if (pcount != 2) { textBox1.Text = textBox2.Text = textBox3.Text = ""; try { textBox2.Text = qs[ans[0]]; textBox3.Text = qs[ans[1]]; } catch { } button1.Enabled = true; button2.Enabled = false; button3.Enabled = false; MessageBox.Show("Объект не определен. Добавьте название объекта с заданными признаками.", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return; } for (int i = 0; i < objs.Count; i++) { if ((objs[i][1] == qs[ans[0]] && objs[i][2] == qs[ans[1]]) || (objs[i][1] == qs[ans[1]] && objs[i][2] == qs[ans[0]])) { MessageBox.Show("Объект: " + objs[i][0], "Объект определен", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } } textBox1.Text = ""; textBox2.Text = qs[ans[0]]; textBox3.Text = qs[ans[1]]; button1.Enabled = true; button2.Enabled = false; button3.Enabled = false; MessageBox.Show("Объект не определен. Добавьте название объекта с заданными признаками.", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } } - Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.