deepika
BAN USER{
char[] arr = new char[] { 'a', 'c', 'c', 'a', 'b', 'a' };
List<char> li = new List<char>();
Dictionary<char, char> dict = new Dictionary<char, char>();
for (int i = 0; i < arr.Length; i++)
{
if(!li.Contains(arr[i]))
{
li.Add(arr[i]);
}
}
Console.WriteLine(li.Count);
Console.ReadLine();
}
Dictionary<int, StringBuilder> dict = new Dictionary<int,StringBuilder>();
int[] arr = new int[] { 1, 2, -3, 2, 3, 4, -6, 1, 2, 3, 4, 5, -8, 5, 6 };
StringBuilder s = null;
for (int i = 0; i < arr.Length; i++)
{
if (i == 0 && arr[0] > 0)
{
s = new StringBuilder();
}
if (arr[i] < 0 )
{
int index = i - s.Length;
dict.Add(index + 1, s);
s = new StringBuilder();
}
else
{
s.Append(arr[i]);
}
}
Console.WriteLine(dict[8]);
Console.ReadLine();
int[] arr = new int[] { 1, 2, 3, 30, 10, 11, 12 };
//int max1 = arr[0], max2 = arr[1], max3 = arr[2];
int n = 4;// input max no of element
int[] max = new int[n]; //
for (int i = 0; i < arr.Length; i++)
{
if (arr[i] > max[0])
{
max[0] = arr[i];
}
for (int j = 0; j < max.Length; j++)
{
bool flag = false;
for (int k = 0; k < j; k++)
{
if (arr[i] < max[k])
flag = true;
else
{
flag = false;
break;
}
}
if (flag && (arr[i] > max[j]))
{
//max[j + 1] = max[j];
//algo to swap all the elments after j such that swap[j+1,j)
for (int l = max.Length -1; l > 0; l--)
{
if (l >= 1)
max[l] = max[l-1];
}
max[j] = arr[i];
//one more loop to replace max array ;
}
}
}
Console.WriteLine(string.Format("max1 : {0}, max2 :{1},max3 : {2},{3}", max[0], max[1], max[2], max[3]));
Console.ReadLine();
int[] arr = new int[] { 1, 2, 3, 30, 10, 11, 12 };
//int max1 = arr[0], max2 = arr[1], max3 = arr[2];
int n = 4;// input max no of element
int[] max = new int[n]; //
for (int i = 0; i < arr.Length; i++)
{
if (arr[i] > max[0])
{
max[0] = arr[i];
}
for (int j = 0; j < max.Length; j++)
{
bool flag = false;
for (int k = 0; k < j; k++)
{
if (arr[i] < max[k])
flag = true;
else
{
flag = false;
break;
}
}
if (flag && (arr[i] > max[j]))
{
//max[j + 1] = max[j];
//algo to swap all the elments after j such that swap[j+1,j)
for (int l = max.Length -1; l > 0; l--)
{
if (l >= 1)
max[l] = max[l-1];
}
max[j] = arr[i];
//one more loop to replace max array ;
}
}
}
Console.WriteLine(string.Format("max1 : {0}, max2 :{1},max3 : {2},{3}", max[0], max[1], max[2], max[3]));
Console.ReadLine();
{
- deepika April 27, 2015char[] arr = new char[] { 'a', 'c', 'c', 'a', 'b', 'a' };
List<char> li = new List<char>();
Dictionary<char, char> dict = new Dictionary<char, char>();
for (int i = 0; i < arr.Length; i++)
{
if(!li.Contains(arr[i]))
{
li.Add(arr[i]);
}
}
Console.WriteLine(li.Count);
Console.ReadLine();
}