Напиши код на C# в файле набор строк необходимо выдать количество строк в которых нет…
- User
Напиши код на C# в файле набор строк необходимо выдать количество строк в которых нет повторяющихся символов
- Assistant
using System;
namespace UniqueCharacters { class Program { static void Main(string[] args) { string[] lines = System.IO.File.ReadAllLines(@"C:\input.txt"); int count = 0;
foreach (string line in lines) { bool isUnique = true; for (int i = 0; i < line.Length - 1; i++) { for (int j = i + 1; j < line.Length; j++) { if (line[i] == line[j]) { isUnique = false; break; } } if (!isUnique) { break; } } if (isUnique) { count++; } } Console.WriteLine("Number of lines with unique characters: " + count); } }}
- User
Solve task by writing code in C#. Output unclosed brackets in string (){}[])))(((()))[][][]{}{}{}{()(){}}{}{()([][{}{})
- Assistant
Here is the code in C# that outputs the unclosed brackets in the given string:
using System; using System.Collections.Generic; class Program { static void Main() { string s = "(){}[])))(((()))[][][]{}{}{}{()(){}}{}{([][{)})"; // the given string Stack<int> stack = new Stack<int>(); for (int i = 0; i < s.Length; i++) { char c = s[i]; if (c == '(' || c == '{' || c == '[') { stack.Push(i); } else if (c == ')' || c == '}' || c == ']') { if (stack.Count == 0) { Console.WriteLine("Unexpected closing bracket at position " + i); } else { int start = stack.Pop(); if (c == ')' && s[start] != '(' || c == '}' && s[start] != '{' || c == ']' && s[start] != '[') { Console.WriteLine("Mismatched brackets at positions " + start + " and " + i); } } } } while (stack.Count > 0) { Console.WriteLine("Unclosed bracket at position " + stack.Pop()); } } }