Напиши код на 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()); } } }This program uses a stack to keep track of the positions of opening brackets. When a closing bracket is encountered, it pops the last position from the stack and checks if the brackets match. If there is a mismatch, it reports the positions of the mismatched brackets. If there are still brackets on the stack after iterating through the string, it reports their positions as unclosed brackets.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.