-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathOccOfEachChar.cs
43 lines (38 loc) · 1.03 KB
/
OccOfEachChar.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApp1.StringEx
{
class OccOfEachChar
{
public void OccOfEach(char[] ch)
{
for (int i = 0; i < ch.Length; i++)
{
if (ch[i] == '*')
continue;
int count = 1;
for (int j = i + 1; j < ch.Length; j++)
{
if (ch[i] == ch[j])
{
count++;
ch[j] = '*';
}
}
Console.WriteLine(ch[i] + "appears" + count + "times");
}
}
static void Main(string[] args)
{
Console.WriteLine("Enter the String: ");
String s = Console.ReadLine();
char[] ch = s.ToCharArray();
OccOfEachChar o = new OccOfEachChar();
o.OccOfEach(ch);
Console.ReadLine();
}
}
}