![]() |
|
|
![]()
|
|
| Алинамалина |
|
|||
|
Новичок Профиль Группа: Участник Сообщений: 1 Регистрация: 25.5.2012 Репутация: нет Всего: нет |
Необходимо составить выходящие методы к каждой из задач.
//Задание 1 Console.WriteLine("Задание 1. Определить частоту вхождения каждой буквы"); Console.WriteLine("Введите текст:"); string input = Console.ReadLine(); input = input.ToLower(); string chars = " .,!?;:"; int count = 0; for (int i = 0; i < input.Length; i++) { bool alreadychecked = false; for (int j = 0; j < chars.Length; j++) { if (input[i] == chars[j]) { alreadychecked = true; break; } } if (alreadychecked) continue; chars += input[i]; for (int j = 0; j < input.Length; j++) if (input[i] == input[j]) count++; Console.WriteLine("Буква '{0}' входит в текст {1} раз", input[i], count); } //Задание 2 Console.WriteLine("\nЗадание 2. Определить количество слов с заданным символом"); Console.WriteLine("Введите текст:"); input = Console.ReadLine(); Console.WriteLine("Введите символ:"); string[] words = input.Split(' '); string symbol = Console.ReadLine(); count = 0; for (int i = 0; i < words.Length; i++) { for (int j = 0; j < words[i].Length; j++) if (words[i][j] == symbol[0]) { count++; break; } } Console.WriteLine("Символ '{0}' встречается в {1} словах", symbol[0], count); //Задание 3 Console.WriteLine("\nЗадание 3. Вывести введеный текст без цифр и пробелов."); Console.WriteLine("Введите текст:"); input = Console.ReadLine(); string toremove = "0123456789 "; for (int i = 0; i < input.Length; i++) { for (int j = 0; j < toremove.Length; j++) { if (input[i] == toremove[j]) { input = input.Remove(i, 1); i--; break; } } } int firstchar = Convert.ToInt32(input[0]); if ((firstchar > 96 && firstchar < 123) || (firstchar > 1071 && firstchar < 1104)) { input = input.Remove(0, 1); input = Convert.ToChar(firstchar - 32) + input; } Console.WriteLine("Результат:\n{0}", input); //Задание 4 Console.WriteLine("\nЗадание 4. Определить количество слов с заданным символом"); Console.WriteLine("Введите текст:"); input = Console.ReadLine(); Console.WriteLine("Введите символ:"); words = input.Split(' '); symbol = Console.ReadLine(); count = 0; for (int i = 0; i < words.Length; i++) { for (int j = 0; j < words[i].Length; j++) if (words[i][j] == symbol[0]) { count++; break; } } Console.WriteLine("Символ '{0}' встречается в {1} словах", symbol[0], count); //Задание 5 Console.WriteLine("\nЗадание 5. Удалить из текста все гласные."); Console.WriteLine("Введите текст:"); input = Console.ReadLine(); toremove = "аеёиоуыэюяaeiouy"; count = 0; for (int i = 0; i < input.Length; i++) { for (int j = 0; j < toremove.Length; j++) { if (input[i] == toremove[j]) { input = input.Remove(i, 1); i--; count++; break; } } } Console.WriteLine("Результат:\n{0}", input); Console.WriteLine("Количество удалений: {0}", count); //Задание 6 Console.WriteLine("\nЗадание 6. Определить слово максимальной длины."); input = Console.ReadLine(); words = input.Split(' '); int maxlength = 0, index = 0; for (int i = 0; i < words.Length; i++) { if (words[i].Length > maxlength) { maxlength = words[i].Length; index = i; } } Console.WriteLine("Самое длинное слово: '{0}'", words[index]); //Задание 7 Console.WriteLine("\nЗадание 7. Удалить из текста повторяющиеся слова."); for (int i = 0; i < words.Length; i++) { for (int j = i + 1; j < words.Length; j++) { if (words[i] == words[j]) words[j] = null; } } string output = ""; for (int i = 0; i < words.Length; i++) if(words[i] != null) output += words[i] + " "; Console.WriteLine("Результат:\n{0}", output); //Задание 8 Console.WriteLine("\nЗадание 8. Удалить из текста заданный пользователем символ."); Console.WriteLine("Введите текст:"); input = Console.ReadLine(); Console.WriteLine("Введите символ:"); symbol = Console.ReadLine(); for (int i = 0; i < input.Length; i++) { if (input[i] == symbol[0]) { input = input.Remove(i, 1); i--; } } Console.WriteLine("Результат: \n{0}", input); //Задание 9 Console.WriteLine("\nЗадание 9. Проверить правильность расстановки скобок."); Console.WriteLine("Введите текст:"); input = Console.ReadLine(); int openbrackets = 0; int closebrackets = 0; for (int i = 0; i < input.Length; i++) { if (input[i] == '(') openbrackets++; if (input[i] == ')') closebrackets++; } if (openbrackets > closebrackets) Console.WriteLine("Не хватает закрывающих скобок: {0}", openbrackets - closebrackets); if (closebrackets > openbrackets) Console.WriteLine("Не хватает открывающих скобок: {0}", closebrackets - openbrackets); if (openbrackets == closebrackets) Console.WriteLine("Скобки расставлены правильно"); //Задание 10 Console.WriteLine("\nЗадание 10. Присвоить первой переменной значение второй и наоборот без введения дополнительных переменных."); string str1 = "Привет.", str2 = "Здравствуйте."; Console.WriteLine("Значение первой переменной: '{0}'\nЗначение второй переменной: '{1}'", str1, str2); str2 += str1; str1 = str2.Replace(str1, ""); str2 = str2.Replace(str1, ""); Console.WriteLine("Результат:"); Console.WriteLine("Значение первой переменной: '{0}'\nЗначение второй переменной: '{1}'", str1, str2); Прошу вас, если вы не можете составить метод, то вкратце объясните мне, чайнику, как это сделать. Заранее спасибо. |
|||
|
||||
| daabdul |
|
|||
|
Новичок Профиль Группа: Участник Сообщений: 1 Регистрация: 25.5.2012 Репутация: нет Всего: нет |
присоединяюсь, помогите кто может!
|
|||
|
||||
![]()
|
| Добро пожаловать в раздел "Другие языки" форума Vingrad! | |
|
|
Раздел посвящён различным языкам программирования, для которых (в силу невысокой популярности) нет отдельного раздела (GPSS, Lua, MATLAB, Ada, Forth, Smalltalk, Tcl, REXX, AWK и др.)
Приятного времяпрепровождения! С уважением, Void, kemiisto . |
| 0 Пользователей читают эту тему (0 Гостей и 0 Скрытых Пользователей) | |
| 0 Пользователей: | |
| « Предыдущая тема | Другие языки | Следующая тема » |
|
|
По вопросам размещения рекламы пишите на vladimir(sobaka)vingrad.ru
Отказ от ответственности Powered by Invision Power Board(R) 1.3 © 2003 IPS, Inc. |