- Notifications
You must be signed in to change notification settings - Fork91
Using arrays
NN--- edited this pageApr 18, 2012 ·4 revisions
- Category: Arrays, Hash Tables and Dictionaries
- Description: Create a histogram of the occurrences of particular letters
- Code:
using System.Console;def results =array('Z'+1-'A') :array[int];def data ="The quick brown fox jumps over the lazy dog";foreach (cwhen c >='A' && c <='Z'in data.ToUpper()with i) results[c :int-'A']++;foreach (cin ['A' ..'Z']) WriteLine($"Number of '$c' characters = $(results[c - 'A' : int])");
Execution Result:
Number of 'A' characters = 1Number of 'B' characters = 1Number of 'C' characters = 1Number of 'D' characters = 1Number of 'E' characters = 3Number of 'F' characters = 1Number of 'G' characters = 1Number of 'H' characters = 2Number of 'I' characters = 1Number of 'J' characters = 1Number of 'K' characters = 1Number of 'L' characters = 1Number of 'M' characters = 1Number of 'N' characters = 1Number of 'O' characters = 4Number of 'P' characters = 1Number of 'Q' characters = 1Number of 'R' characters = 2Number of 'S' characters = 1Number of 'T' characters = 2Number of 'U' characters = 2Number of 'V' characters = 1Number of 'W' characters = 1Number of 'X' characters = 1Number of 'Y' characters = 1Number of 'Z' characters = 1[Copyright ©](Terms of use, legal notice)