Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 05. Digits, Letters and Other
- Write a program that receives a single string and on the first line prints all the digits, on the second – all the letters, and on the third – all the other characters. There will always be at least one digit, one letter and one other characters.
- Examples
- Input Output
- Agd#53Dfg^&4F53 53453
- AgdDfgF
- #^&
- Hints
- • Read the input.
- • Use loop to iterate through all characters in the text. If the char is digit print it, otherwise ignore it.
- o Use char.IsDigit(char symbol)
- • Do the same for the letters and other chars
- o Find something like IsDigit method for the letters.
- using System;
- using System.Collections.Generic;
- namespace ExamResults
- {
- class Program
- {
- static void Main(string[] args)
- {
- var anySymbols = Console.ReadLine();
- var allDigits = "";
- var allLetters = "";
- var allOthers = "";
- foreach (var item in anySymbols)
- {
- if (Char.IsLetterOrDigit(item))
- {
- if (Char.IsDigit(item))
- {
- allDigits += item;
- }
- else
- {
- allLetters += item;
- }
- }
- else
- {
- allOthers += item;
- }
- }
- var result = new List<string>();
- result.Add(allDigits);
- result.Add(allLetters);
- result.Add(allOthers);
- Console.WriteLine(string.Join("\n", result));
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment