.NET 3.x Поиск совпадений в строках циклом - C#
Формулировка задачи:
Поиск совпадений в строках циклом
Проверте товарищи правильно , я использую поиск совпадений строк циклом ?
Листинг программы
- using System;
- using System.Collections.Generic;
- using System.IO;
- using System.Text;
- namespace ConsoleApplication1
- {
- class Program
- {
- static void Main(string[] args)
- {
- Title("Test");
- string[] find = File.ReadAllLines("111.txt");
- string[] scan = File.ReadAllLines("111.txt");
- for (int i = 0; i < find.Length; i++)
- {
- for (int j = 0; j < scan.Length; j++)
- {
- if (i<j)
- {
- if(find[i].Trim()==scan[j])
- Console.WriteLine(j+1); // строки нумерованые совпадения
- }
- }
- }
- Console.ReadKey(true);
- }
- static void Title(string t)
- {
- Console.Title = t;
- Console.BackgroundColor=ConsoleColor.DarkCyan;
- Console.Clear();
- Console.ForegroundColor=ConsoleColor.White;
- }
- }
- }
Кажется нашол отсеить похожие
Листинг программы
- using System;
- using System.Collections.Generic;
- using System.Diagnostics;
- using System.IO;
- using System.Text;
- using System.Linq;
- namespace ConsoleApplication1
- {
- class Program
- {
- static void Main(string[] args)
- {
- Title("Test");
- int k = 0;
- string txt=String.Empty;
- string[] find = File.ReadAllLines("111.txt");
- List<string> list = new List<string>();
- for (int i = 0; i < find.Length; i++)
- {
- list.Add(find[i]);
- }
- List<string> distinct = list.Distinct().ToList();
- for (int i = 0; i < distinct.Count; i++)
- {
- Console.WriteLine((i+1)+" :"+distinct[i]);
- }
- Console.ReadKey(true);
- }
- static void Title(string t)
- {
- Console.Title = t;
- Console.BackgroundColor=ConsoleColor.DarkCyan;
- Console.Clear();
- Console.ForegroundColor=ConsoleColor.White;
- }
- }
- }
Но все таки надо получить совпадения ))
До пер
Листинг программы
- using System;
- using System.Collections.Generic;
- using System.Diagnostics;
- using System.IO;
- using System.Text;
- using System.Linq;
- namespace ConsoleApplication1
- {
- class Program
- {
- static void Main(string[] args)
- {
- Title("Test");
- int k = 0;
- string txt=String.Empty;
- string[] find = File.ReadAllLines("111.txt");
- List<string> list = new List<string>();
- List<string> distinct = new List<string>();
- for (int i = 0; i < find.Length; i++)
- {
- list.Add(find[i]);
- }
- distinct = list.Distinct().ToList();
- for (int i = 0; i < distinct.Count; i++)
- {
- Console.WriteLine((i+1)+" :"+distinct[i]);
- }
- Console.WriteLine("\n\n");
- for (int i = 0; i < find.Length; i++)
- {
- for (int j = i+1; j < find.Length; j++)
- {
- if (find[i]==find[j])
- {
- Console.WriteLine("Дубликат: "+(j+1));
- break;
- }
- }
- }
- Console.ReadKey(true);
- }
- static void Title(string t)
- {
- Console.Title = t;
- Console.BackgroundColor=ConsoleColor.DarkCyan;
- Console.Clear();
- Console.ForegroundColor=ConsoleColor.White;
- }
- }
- }
Хих сам спросил , сам решил
Пока
Листинг программы
- using System;
- using System.Collections.Generic;
- using System.Diagnostics;
- using System.IO;
- using System.Text;
- using System.Linq;
- namespace ConsoleApplication1
- {
- class Program
- {
- static void Main(string[] args)
- {
- Title("Test");
- int k = 0;
- string txt=String.Empty;
- string[] find = File.ReadAllLines("111.txt");
- List<string> list = new List<string>();
- List<string> distinct = new List<string>();
- for (int i = 0; i < find.Length; i++)
- {
- list.Add(find[i]);
- }
- Console.WriteLine("Список вместе с Дубликатами\n");
- for (int i = 0; i < list.Count; i++)
- {
- Console.WriteLine((i+1)+" :{0}",list[i]);
- }
- distinct = list.Distinct().ToList();
- Console.WriteLine("\n\n");
- Console.WriteLine("Список без Дубликатов\n");
- for (int i = 0; i < distinct.Count; i++)
- {
- Console.WriteLine((i+1)+" :"+distinct[i]);
- }
- Console.WriteLine("\n\n");
- Console.WriteLine("Список индексов Дубликатов\n");
- for (int i = 0; i < find.Length; i++)
- {
- for (int j = i+1; j < find.Length; j++)
- {
- if (find[i]==find[j])
- {
- Console.WriteLine("Дубликат: "+(j+1));
- break;
- }
- }
- }
- Console.ReadKey(true);
- }
- static void Title(string t)
- {
- Console.Title = t;
- Console.BackgroundColor=ConsoleColor.DarkCyan;
- Console.Clear();
- Console.ForegroundColor=ConsoleColor.White;
- }
- }
- }
Решение задачи: «.NET 3.x Поиск совпадений в строках циклом»
textual
Листинг программы
- private void button2_Click(object sender, EventArgs e)
- {
- int dat1 = 0, dat2 = 0,k=0;
- int[] del = null;
- dat1 = dataGridView1.Rows.Count - 1;
- dat2 = dataGridView2.Rows.Count - 1;
- List<string> list = new List<string>();
- List<string> distinct = new List<string>();
- if (dat1==dat2)
- {
- using (StreamWriter sw=new StreamWriter("dell.tmp",false,Encoding.GetEncoding(1251)))
- {
- for (int i = 0; i < dat2; i++)
- {
- for (int j = i + 1; j < dat2; j++)
- {
- if (dataGridView2.Rows[i].Cells[0].Value.ToString() == dataGridView2.Rows[j].Cells[0].Value.ToString())
- {
- sw.WriteLine(j);
- }
- }
- }
- }
- if (File.Exists("dell.tmp") == true)
- {
- string[] dellm = File.ReadAllLines("dell.tmp");
- for (int i = 0; i < dellm.Length; i++)
- {
- //MessageBox.Show(dataGridView2.Rows[Convert.ToInt32(dellm[i])].Cells[0].Value.ToString() + "\n" + dataGridView1.Rows[Convert.ToInt32(dellm[i])].Cells[0].Value.ToString());
- //MessageBox.Show(dellm[i]);
- dataGridView1.Rows.RemoveAt(Convert.ToInt32(dellm[(i)]));
- dataGridView2.Rows.RemoveAt(Convert.ToInt32(dellm[(i)]));
- }
- File.Delete("dell.tmp");
- }
- label1.Text = "Lines: " + (dataGridView1.Rows.Count - 1);
- label2.Text = "Lines: " + (dataGridView2.Rows.Count - 1);
- MessageBox.Show("Проверка окончена!","INFO",MessageBoxButtons.OK,MessageBoxIcon.Information);
- }
- else
- {
- MessageBox.Show("Не соответствие строк , и контролеров\n\n"+"Строки: "+dat1+"\nКонтролеры: "+dat2, "ERROR",MessageBoxButtons.OK,MessageBoxIcon.Error);
- }
- }
ИИ поможет Вам:
- решить любую задачу по программированию
- объяснить код
- расставить комментарии в коде
- и т.д