Загрузка данных


using System;
using System.Collections.Generic;
using System.Linq;

public class Program
{
    public static void Main()
    {
        Console.WriteLine("=== Анализ текста и круговая диаграмма ===\n");
        
        // Ввод текста
        Console.Write("Введите текст: ");
        string text = Console.ReadLine();
        
        if (string.IsNullOrEmpty(text))
        {
            Console.WriteLine("Текст не может быть пустым!");
            return;
        }
        
        // Подсчёт символов (игнорируем регистр)
        Dictionary<char, int> charCount = new Dictionary<char, int>();
        
        foreach (char c in text)
        {
            char lowerChar = char.ToLower(c);
            if (charCount.ContainsKey(lowerChar))
            {
                charCount[lowerChar]++;
            }
            else
            {
                charCount[lowerChar] = 1;
            }
        }
        
        // Сортируем по убыванию количества
        var sortedChars = charCount.OrderByDescending(x => x.Value).ToList();
        
        // Вывод статистики
        Console.WriteLine("\n" + new string('=', 50));
        Console.WriteLine("\nСТАТИСТИКА СИМВОЛОВ:\n");
        Console.WriteLine($"Всего символов: {text.Length}");
        Console.WriteLine($"Уникальных символов: {charCount.Count}\n");
        
        foreach (var item in sortedChars)
        {
            double percentage = (double)item.Value / text.Length * 100;
            Console.WriteLine($"'{item.Key}': {item.Value} раз(а) ({percentage:F1}%)");
        }
        
        // Построение круговой диаграммы
        Console.WriteLine("\n" + new string('=', 50));
        Console.WriteLine("\nКРУГОВАЯ ДИАГРАММА:\n");
        
        DrawPieChart(sortedChars, text.Length);
    }
    
    static void DrawPieChart(List<KeyValuePair<char, int>> data, int total)
    {
        // Цвета для секторов
        ConsoleColor[] colors = {
            ConsoleColor.Red, ConsoleColor.Green, ConsoleColor.Blue,
            ConsoleColor.Yellow, ConsoleColor.Cyan, ConsoleColor.Magenta,
            ConsoleColor.DarkRed, ConsoleColor.DarkGreen, ConsoleColor.DarkBlue,
            ConsoleColor.DarkYellow
        };
        
        // Максимальное количество отображаемых секторов (остальные объединяем в "Другие")
        int maxSectors = 8;
        List<KeyValuePair<char, int>> displayData = new List<KeyValuePair<char, int>>();
        
        if (data.Count > maxSectors)
        {
            int othersCount = 0;
            for (int i = maxSectors; i < data.Count; i++)
            {
                othersCount += data[i].Value;
            }
            
            for (int i = 0; i < maxSectors; i++)
            {
                displayData.Add(data[i]);
            }
            
            if (othersCount > 0)
            {
                displayData.Add(new KeyValuePair<char, int>('?', othersCount));
            }
        }
        else
        {
            displayData = data;
        }
        
        // Рисуем круговую диаграмму (ASCII art)
        int width = 40;
        int height = 20;
        char[,] chart = new char[height, width];
        
        // Заполняем фон пробелами
        for (int y = 0; y < height; y++)
        {
            for (int x = 0; x < width; x++)
            {
                chart[y, x] = ' ';
            }
        }
        
        // Рисуем круг
        int centerX = width / 2;
        int centerY = height / 2;
        int radius = 8;
        
        // Вычисляем углы для каждого сектора
        List<(int startAngle, int endAngle, char symbol)> sectors = new List<(int, int, char)>();
        int currentAngle = 0;
        
        for (int i = 0; i < displayData.Count; i++)
        {
            int angleSize = (int)((double)displayData[i].Value / total * 360);
            if (i == displayData.Count - 1 && currentAngle + angleSize < 360)
            {
                angleSize = 360 - currentAngle;
            }
            
            sectors.Add((currentAngle, currentAngle + angleSize, GetSymbolForChar(displayData[i].Key)));
            currentAngle += angleSize;
        }
        
        // Заполняем точки круга
        for (int y = 0; y < height; y++)
        {
            for (int x = 0; x < width; x++)
            {
                int dx = x - centerX;
                int dy = y - centerY;
                double distance = Math.Sqrt(dx * dx + dy * dy);
                
                if (distance >= radius - 1 && distance <= radius + 1)
                {
                    chart[y, x] = '●';
                }
                else if (distance < radius - 1)
                {
                    double angle = Math.Atan2(dy, dx) * 180 / Math.PI;
                    if (angle < 0) angle += 360;
                    
                    for (int s = 0; s < sectors.Count; s++)
                    {
                        if (angle >= sectors[s].startAngle && angle < sectors[s].endAngle)
                        {
                            chart[y, x] = sectors[s].symbol;
                            break;
                        }
                    }
                }
            }
        }
        
        // Выводим диаграмму
        for (int y = 0; y < height; y++)
        {
            Console.Write("  ");
            for (int x = 0; x < width; x++)
            {
                if (chart[y, x] != ' ')
                {
                    char symbol = chart[y, x];
                    if (symbol == '●')
                    {
                        Console.ForegroundColor = ConsoleColor.White;
                        Console.Write(symbol);
                    }
                    else
                    {
                        // Находим цвет для символа
                        for (int i = 0; i < sectors.Count; i++)
                        {
                            if (sectors[i].symbol == symbol)
                            {
                                Console.ForegroundColor = colors[i % colors.Length];
                                break;
                            }
                        }
                        Console.Write(symbol);
                    }
                }
                else
                {
                    Console.Write(' ');
                }
            }
            Console.ResetColor();
            Console.WriteLine();
        }
        
        // Легенда
        Console.WriteLine("\nЛЕГЕНДА:\n");
        for (int i = 0; i < displayData.Count; i++)
        {
            double percentage = (double)displayData[i].Value / total * 100;
            Console.ForegroundColor = colors[i % colors.Length];
            
            string symbol = displayData[i].Key == '?' ? "Другие" : $"'{displayData[i].Key}'";
            Console.Write($"  {symbol}");
            Console.ResetColor();
            Console.WriteLine($": {displayData[i].Value} ({percentage:F1}%)");
        }
    }
    
    static char GetSymbolForChar(char c)
    {
        // Возвращаем символ для отображения в диаграмме
        if (c == ' ') return '␣';
        if (c == '\n') return '↵';
        if (c == '\t') return '→';
        return c;
    }
}


=== Анализ текста и круговая диаграмма ===

Введите текст: hello world

==================================================

СТАТИСТИКА СИМВОЛОВ:

Всего символов: 10
Уникальных символов: 7

'l': 3 раз(а) (30.0%)
'o': 2 раз(а) (20.0%)
'h': 1 раз(а) (10.0%)
'e': 1 раз(а) (10.0%)
' ': 1 раз(а) (10.0%)
'w': 1 раз(а) (10.0%)
'r': 1 раз(а) (10.0%)
'd': 1 раз(а) (10.0%)

==================================================

КРУГОВАЯ ДИАГРАММА:

       ●●●       
     ●●●●●●     
    ●●●●●●●●    
   ●●●●●●●●●●   
   ●●●●●●●●●●   
  ●●●●●●●●●●●●  
  ●●●●●●●●●●●●  
  ●●●●●●●●●●●●  
  ●●●●●●●●●●●●  
  ●●●●●●●●●●●●  
  ●●●●●●●●●●●●  
   ●●●●●●●●●●   
   ●●●●●●●●●●   
    ●●●●●●●●    
     ●●●●●●     
       ●●●       

ЛЕГЕНДА:

█ 'l': 3 (30.0%)
▓ 'o': 2 (20.0%)
▒ 'h': 1 (10.0%)
░ 'e': 1 (10.0%)
● '␣': 1 (10.0%)
◆ 'w': 1 (10.0%)
■ 'r': 1 (10.0%)
▲ 'd': 1 (10.0%)