-
Notifications
You must be signed in to change notification settings - Fork 18
/
CountClumps.cs
84 lines (82 loc) · 2.29 KB
/
CountClumps.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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication190
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("CountClumps");
Console.WriteLine("\n");
Console.WriteLine("Enter the Maximum Range for the input array:");
int N = Convert.ToInt32(Console.ReadLine());
int[] a = new int[N];
int i, j, count = 0;
Console.WriteLine("Enter the values:");
for (i = 0; i < N; i++)
{
a[i] = Convert.ToInt32(Console.ReadLine());
}
Console.WriteLine("THe array contains following values:");
for (i = 0; i < N; i++)
{
Console.Write("{0} ", a[i]);
}
Console.WriteLine("\n");
for (i = 0; i < N; i++)
{
for (j = i + 1; j < N; j++)
{
if (a[i] == a[j])
{
count++;
i++;
break;
}
else
{
break;
}
}
}
int diff = 0, count1 = 0;
Console.WriteLine("\n");
for (i = 0; i < N; i++)
{
for (j = i + 1; j < N; j++)
{
if (a[i] == a[j])
{
diff = a[i] - a[j];
if (diff == 0)
{
count1++;
break;
}
else
{
break;
}
}
else
{
break;
}
}
}
Console.WriteLine("\n");
if (count1==N-1)
{
Console.WriteLine(a[0]);
}
else
{
Console.WriteLine(count);
}
Console.ReadLine();
}
}
}