You are on page 1of 197

//////////// 1) two same string return reverse and joining them

////i/p:str1=dbe,str2:dbe pos:2
////o/p:ebdebd

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Chap13
{
class Program
{
public static string stringEqualCheck(string str1, string str2, int pos)
{
// fill your code here
string str3 = null;
string s1 = str1.Substring(pos - 1);
string s2 = str2.Substring(pos - 1);
if (s1 == s2)
{
char[] a = str1.ToCharArray();
Array.Reverse(a);
string b = new string(a);//charecter array to string conversion/
/
char[] c = str2.ToCharArray();
Array.Reverse(c);
string d = new string(c);
str3 = b + d;
return str3;
}
else
return ("not equal in length");

}
public static void Main(string[] args)
{
Console.WriteLine("Enter the 1st string");
string s = Console.ReadLine();
Console.WriteLine("Enter the 2nd string");
string t = Console.ReadLine();
Console.WriteLine("Enter the position");
int j = Convert.ToInt32(Console.ReadLine());
string result = stringEqualCheck(s, t, j);
Console.WriteLine(result);
Console.ReadLine();
}
}
}
////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////
////2)take a integer array and sum of the individual array elements digits and a
nother integer array sorted by desc
////1/p: arr size=4
////element=12,25,55,23
////o/p: 10,7,5,3

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication130
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("enter the array size");
int n = Convert.ToInt32(Console.ReadLine());
int[] a = new int[n];//converting integer to integer array
Console.WriteLine("enter the array element");
for (int i = 0; i < n; i++)
{
a[i] = Convert.ToInt32(Console.ReadLine());

}
int[] p = decendingsum(a);
Console.WriteLine("THE RESULTANT ARRAY IS");
foreach (var item in p)
{
Console.WriteLine(item);
}
Console.ReadLine();
}
public static int[] decendingsum(int[] m)
{
List<int> li = new List<int>();
int sum = 0;
for (int i = 0; i < m.Length; i++)
{
while (m[i] != 0)
{
int rem = m[i] % 10;
sum = sum + rem;
m[i] = m[i] / 10;
}
li.Add(sum);
sum = 0;

}
li.Sort();
li.Reverse();

int[] s = li.ToArray();//convering list to integer array


return (s);
}
}
}
////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////
//3)take an integer array and an iteger,if the integer matches with the array el
ements last digit,then return those digits in a int[]
//else return -1
//i/p: aar size: 4 elements:12,35,52,2 input:2
//o/p: 2,12,52

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace chap8
{
class Program
{
public static int[] FindLast(int[] input1, int input2)
{
int[] a = { -1 };
List<int> li = new List<int>();
foreach (var item in input1)
{
string s = Convert.ToString(item);
string s1 = Convert.ToString(input2);
if (s.EndsWith(s1) == true && li.Contains(item) == false)
{
li.Add(item);
}
}
if (li.Count == 0)
return a;
li.Sort();
return li.ToArray();
}
static void Main(string[] args)
{
int[] a = { 123, 34, 331, 43, 13, 98 };
int b = 3;
int[] result = FindLast(a, b);
foreach (var item in result)
{
Console.WriteLine(item);
}
Console.ReadLine();
}
}
}
////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////
//4)convert numbers into words
//i/p:123
//o/p:one two three

using System;
using System.Collections.Generic;
class onetowthree
{
public static string One23(int input1)
{
string s = "";
string[] words =
{"zero","one","two","three","four","five","six","seven",
"eight","nine"};
List<int> li = new List<int>();
while (input1 != 0)
{
int t = input1 % 10;
li.Add(t);
input1 = input1 / 10;
}
li.Reverse();
foreach (var item in li)
{
s = s + words[item] + " ";
}
return s;
}
static void Main(string[] args)
{
int a = Convert.ToInt32(Console.ReadLine());
Console.WriteLine(One23(a));
Console.ReadLine();
}
}
////////////////////////////////////////////////////////////////////////////////
////////////////////
//5)sum of the digits of a number if sum is greater than 9 then sum again those
digits;
//i/p:15 o/p:1+5 =6 i/p: 78 o/p: 7+8=15 -> 1+5 = 6

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
class UserProgramCode
{
public static int getDigitSum(int input)
{
int sum = 0;
int sum1 = 0;
int i = 0;
int j = 0;
while (input > 0)
{
i = (input % 10);
sum = sum + i;
input = input / 10;
}
if (sum < 10)
{
return sum;
}
else
{
while (sum > 0)
{
j = (sum % 10);
sum1 = sum1 + j;
sum = sum / 10;
}
}
return sum1;
}
}
class Program
{
public static void Main(string[] args)
{
int input, output;
input = Convert.ToInt32(Console.ReadLine());
output = UserProgramCode.getDigitSum(input);
Console.WriteLine(output);
Console.ReadLine();
}
}

////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////

//6) triplet number


//i/p
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace triplet
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("enter no");
int a = Convert.ToInt32(Console.ReadLine());
string[] result = triplet(a);
foreach (var item in result)
{
Console.WriteLine(item);
break;
}
Console.ReadLine();
}
public static string[] triplet(int input)
{
List<string> li = new List<string>();
int sum = 0;
for (int m = 1; m < input; m++)
{
for (int k = m + 1; k < input; k++)
{
for (int l = k + 1; l < input; l++)
{
sum = m + k + l;
if (sum == input)
{
li.Add(l + "," + k + "," + m);
//li.Sort();
li.Reverse();

}
}
}
string[] s = li.ToArray();
return s;

}
}
}
///////////// triplet need to clear
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication3
{
class Program
{
public static int[] ab(int[] a, int b)
{
int s = 0, c = 0;
List<int> l = new List<int>();
for (int z = 0; z < a.Length; z++)
{
for (int t = z + 1; t < a.Length - 1; t++)
{
if (a[z] == a[t])
{
l.Add(-3);
return l.ToArray();
}
}
}
foreach (int u in a)
{
if (u < 0)
{
l.Add(-2);
return l.ToArray();
}
}
for (int i = 0; i < a.Length; i++)
{
for (int j = 0; j < a.Length; j++)
{
for (int k = 0; k < a.Length; k++)
{
//if (a[i] == a[j] && a[j] == a[k] && a[i] == a[k])
//{
// l.Add(-1);
// return l.ToArray();
//}
//else
if (a[i] != a[j] && a[j] != a[k] && a[i] != a[k])
{
s = a[i] + a[j] + a[k];
if (s == b)
{
c++;
l.Add(a[i]);
l.Add(a[j]);
l.Add(a[k]);

}
}
}

}
return l.ToArray();

static void Main(string[] args)


{
int[]a={2,3,4,5,6,7,8,9};
int p =24;
int[] result = ab(a, p);
foreach (var item in result)
{

Console.WriteLine(item);

}
Console.ReadLine();
}
}
}

//correct triplet
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
class a
{
public static int[] so3(int[] a, int n)
{
int[] op = new int[3];
try
{
var x = (from pr in a from pr1 in a from pr2 in a where ((pr + pr1 +
pr2 == n) && (pr != pr1) && (pr1 != pr2) && (pr2 != pr)) select pr).First();
var y = (from pr in a from pr1 in a from pr2 in a where ((pr + pr1 +
pr2 == n) && (pr != pr1) && (pr1 != pr2) && (pr2 != pr)) select pr1).First();
var z = (from pr in a from pr1 in a from pr2 in a where ((pr + pr1 +
pr2 == n) && (pr != pr1) && (pr1 != pr2) && (pr2 != pr)) select pr2).First();

op[0] = x;
op[1] = y;
op[2] = z;
return op;
}
catch
{
op[0] = -1;
Array.Resize(ref op, 1);
return op;
}
}
static void Main(string[] args)
{
int n = Convert.ToInt32(Console.ReadLine());
int[] ip = { 12, 9, 3, 10, 1, 1, 5, 6 };
int[] op = so3(ip, n);
for (int i = 0; i < op.Length; i++)
{
Console.WriteLine(op[i]);
}
Console.ReadLine();
}
}
..........................or...........................................
In an array add of any two digits makes third digit (input by user)
Ip= 1 2 3 5 6
Ip1=6
Op= 1 2 3
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace StringCount
{
class Program
{
static void Main(string[] args)
{
int s = 0;
int n = Convert.ToInt32(Console.ReadLine());
int[] a = new int[n];
for (int i = 0; i < n; i++)
{
a[i] = Convert.ToInt32(Console.ReadLine());
}
int[] output = new int[3];
int x = Convert.ToInt32(Console.ReadLine());
for (int i = 0; i < a.Length; i++)
{
for (int j = i + 1; j < a.Length; j++)
{
for (int k = j+1; k < a.Length; k++)
{
if ((a[i] + a[j] + a[k]) == x && a[i] != a[j] &&
a[k] != a[j] && a[k] != a[i])
{
s = 1;
output[0] = a[i];
output[1] = a[j];
output[2] = a[k];
}
}
}
}
if (s > 0)
{
foreach (int i in output)
{
Console.WriteLine(i);
}
}
else
Console.WriteLine("No such pair exists");
Console.ReadKey();
}
}
}

////////////////////////////////////////////////////////////////////////////////
///////////////////
//7)GRANTING NUMBER I/P:123(INCRESING) O/P:1
//I/P:210(DECREASING) O/P :-1;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace GrantingNumber
{
class Program
{
public static int Grant(int input)
{
int[] arr = new int[5];
int i = 0;
int output = 0;
int flag = 0;
while (input != 0)
{
int temp = input % 10;
arr[i] = temp;
input = input / 10;
i++;
}
Array.Resize(ref arr, i);

for (int j = 0; j < i - 1; j++)


{
if (arr[j] < arr[j + 1])
{
flag = 0;
}
else
{
flag = 1;
break;
}
}
if (flag == 1)
{
for (int j = 0; j < i - 1; j++)
{
if (arr[j] > arr[j + 1])
{
flag = 0;
}
else
{
flag = 2;
break;
}
}
}
if (flag == 1)
{
output = -1;
}
if (flag == 0)
{
output = 1;
}
return output;
}
static void Main(string[] args)
{
int n = int.Parse(Console.ReadLine());
int output = Grant(n);
Console.WriteLine(output);
}
}
}
////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////
//8)longest pallindrome with count

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace LagestPalindromeInaString
{
class Program
{
static void Main(string[] args)
{
string s = "seaesstringnirts";
string m = "";
int len = 0;
char[] ch = s.ToCharArray();
for (int i = 0; i < ch.Length; i++)
{
for (int j = i + 1; j < ch.Length; j++)
{
if (ch[i] == ch[j] && i != j)
{
string k = s.Substring(i, j - i + 1);
char[] c = k.ToCharArray();
Array.Reverse(c);
StringBuilder sb = new StringBuilder();
foreach (char p in c)
sb.Append(p);
if (k == sb.ToString())
{
if (len < k.Length)
{
len = k.Length;
m = k;
}
}
}
}
}
Console.WriteLine(m + " " + len);
}
}
}
//another process longest pallindrome
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace LongestPalindrome
{
class Program
{
static string LargestPalindrome(string input)
{
int rightIndex = 0, leftIndex = 0;
var x = "";
string currentPalindrome = string.Empty;
string longestPalindrome = string.Empty;
for (int currentIndex = 1; currentIndex < input.Length - 1; currentI
ndex++)
{
leftIndex = currentIndex - 1;
rightIndex = currentIndex + 1;
while (leftIndex >= 0 && rightIndex < input.Length)
{
if (input[leftIndex] != input[rightIndex])
{
break;
}
currentPalindrome = input.Substring(leftIndex, rightIndex -
leftIndex + 1);
if (currentPalindrome.Length > x.Length)
x = currentPalindrome;
leftIndex--;
rightIndex++;
}
}
return x;
}
static void Main(string[] args)
{
Console.WriteLine(LargestPalindrome("madammalayalam"));
Console.ReadLine();
}
}
}
////////////////////////////////////////////////////////////////////////////////
/////////////////////////
//9)permutation of a string
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace LagestPalindromeInaString
{
class Program
{
static void Main(string[] args)
{
string set = Console.ReadLine();
List<string> output = FindPermutations(set);
foreach (var s in output)
{
Console.WriteLine(s);
}
Console.ReadKey();
}
private static List<string> FindPermutations(string set)
{
var output = new List<string>();
if (set.Length == 1)
{
output.Add(set);
}
else
{
var chars = set.ToCharArray();
foreach (var c in chars)
{
var tail = chars.Except(new List<char>() { c });
foreach (var tailPerms in FindPermutations(new string(tail.T
oArray())))
{
output.Add(c + tailPerms);
}
}
}
return output;
}
}
}
////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////
//10)apend $ to smallest string

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication7
{
class Program
{
static void Main(string[] args)
{
int n;
n = int.Parse(Console.ReadLine());
string[] s = new string[n];
for (int i = 0; i < n; i++)
{
s[i] = Console.ReadLine();
}
int m;
m = int.Parse(Console.ReadLine());
char c;
StringBuilder sb = new StringBuilder();
foreach (string s1 in s)
{
char[] c1 = s1.ToCharArray();
if((m-1)<c1.Length)
{
for (int j = 0; j < c1.Length; j++)
{
if (j == (m - 1))
{
c = c1[j];
sb.Append(c);
}

}
}
else
{
c = '$';
sb.Append(c);
}
}
string s2 = sb.ToString();
Console.WriteLine(s2);
}
}
}
////////////////////////////////////////////////////////////////////////////////
///////////////////////////
//11)add even position digits and subtract odd position digits
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace addSumOdd
{
class Class1
{
public static int fun1(int input1)
{
int sum = 0, sum1 = 0, sum2 = 0, rem = 0;
List<int> li = new List<int>();
while (input1 > 0)
{
rem = input1 % 10;
li.Add(rem);
input1 = input1 / 10;
}
li.Sort();
int[] num = li.ToArray();
for (int i = 0; i < num.Length; i++)
{
if (i % 2 == 0)
{
sum1 = sum1 + num[i];
}
else
{
sum2 = sum2 - num[i];
}
sum = sum1 + sum2;
}
return sum;
}
static void Main(string[] args)
{
Console.WriteLine("Enter a number");
int i = Convert.ToInt32(Console.ReadLine());
int result = fun1(i);
Console.WriteLine(result);
Console.ReadLine();
}
}
}
////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////

//12) anagram
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
class Program
{
public int an(string s1, string s2)
{
int l = 0, p = 0;
string[] s3 = s2.Split(' ');

List<char> lc = new List<char>();


char[] c2 = s2.ToCharArray();
foreach (char v in c2)
if (v != ' ')
lc.Add(v);
char[] vv = lc.ToArray();
Array.Sort(vv);
string a1 = new string(vv);
char[] c21 = s1.ToCharArray();
Array.Sort(c21);
string a2 = new string(c21);
if (a1 == a2)
p = 1;

else
p = -1;
return p;
}
static void Main(string[] args)
{
Program p = new Program();
string s7 = "yobbias";
string s8 = "a bboy is";
Console.WriteLine(p.an(s7, s8));
Console.ReadKey();
}
}

////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////
//13)sum of the digits present in a string
////eg.app123e
////output=1+2+3=6
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace SumOfdigitinString
{
class Program
{
static void Main(string[] args)
{
string s = Console.ReadLine();
int result = sumofdigitsinstring(s);
Console.WriteLine(result);
Console.ReadLine();
}
public static int sumofdigitsinstring(string input1)
{
int temp, sum = 0;
StringBuilder sb = new StringBuilder();
// string input1 = "app123e";
char[] ch = input1.ToCharArray();
foreach (char c in ch)
{
if (char.IsDigit(c))
{
sb.Append(c);
}
}
string s = sb.ToString();
int n = int.Parse(s);
while (n > 0)
{
temp = n % 10;
sum = sum + temp;
n = n / 10;
}
return sum;
}
}
}
////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////
//14) add squre between two consecutive numbers
//i/p: array size:5 elements: 3,4,6,8,9
//o/p:3,9,4,6,8,64,9

using System;
using System.Collections.Generic;
using System.Text;
using System.Linq;
namespace NumWords
{
class Program
{
static void Main(string[] args)
{
int n = Convert.ToInt32(Console.ReadLine());
List<int> arr = new List<int>();
int temp = 0;
List<int> l2 = new List<int>();
for (int i = 0; i < n; i++)
{
arr.Add(Convert.ToInt32(Console.ReadLine()));
}
for (int i = 0; i < n - 1; i++)
{
if (arr[i] + 1 == arr[i + 1])
{
temp = (int)Math.Pow(arr[i], 2);
l2.Add(arr[i]); l2.Add(temp);
}
else
{
l2.Add(arr[i]);
}
}
l2.Add(arr[arr.Count - 1]);
for (int i = 0; i < l2.Count; i++)
{
Console.WriteLine(l2[i]);
}
Console.ReadLine();
}
}
}
////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////
//15)append sum of the digits of a string to the end of the string
//i/p: apple1234gh
//o/p:applegh10
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace SumOfdigitinString
{
class Class1
{
public static string fun(string str1)
{
StringBuilder sb = new StringBuilder();
int sum = 0;
string ans1 = "";
string res = "";
char[] ch1 = (from ss in str1 where char.IsLetter(ss) select ss).ToA
rray();
char[] ch = (from s in str1 where char.IsDigit(s) select s).ToArray(
);
foreach (char c in ch)
{
sum += (int)char.GetNumericValue(c);
}
foreach (char c1 in ch1)
{
sb.Append(c1);
}
ans1 = sb.ToString();
res = ans1 + sum.ToString();
return res;
}
static void Main(string[] args)
{
string s = Console.ReadLine();
string RESULT = fun(s);
Console.WriteLine(RESULT);
Console.ReadLine();
}
}
}

////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////
//16) highest difference in a integer array elements where 1st elements next ele
ment
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace _2nd_attempt
{
class Program
{
public static int highestdiff(int[] input)
{
List<int> l = new List<int>();
//List<int>li=new List<int>();
for (int i = 0; i < input.Length - 1; i++)
{
for (int j = i + 1; j < input.Length; j++)
{

if (input[j] > input[i])


{
l.Add(input[j] - input[i]);

}
for (int k = 0; k < input.Length; k++)
{
if (input[k] < 0)
{
return -1;
}
}
int max = l.Max();
return max;

}
static void Main(string[] args)
{
int size = Convert.ToInt32(Console.ReadLine());
int[] number = new int[size];
for (int i = 0; i < size; i++)
{
number[i] = Convert.ToInt32(Console.ReadLine());
}
int result = highestdiff(number);
Console.WriteLine(result);
Console.ReadLine();
}

}
}
////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////
17)CTS-HYD-1234
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication61
{
class Program
{
static void Main(string[] args)
{
string s1 = "CTS-HYD-1234";
string s2 = "hyderbad";
Console.WriteLine(CTSHYD(s1, s2));
Console.ReadLine();
}
private static int CTSHYD(string s1, string s2)
{
if (s1.StartsWith("CTS"))
{
string[] w = s1.Split('-');
if (w[1] == s2.Substring(0, 3).ToUpper())
{
int x;
bool b = int.TryParse(w[2], out x);

if (b == true)
{
return 1;
}
else
return -1;
}
else
return -1;
}
else
return -1;
}
}
}
////////////////////////////////////////////////////////////////////////////////
///////////////////////////////
//18)gyrating number

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace gyrating_number
{
class Program
{
static void Main(string[] args)
{
int size = Convert.ToInt32(Console.ReadLine());
int[] a = new int[size];
for (int i = 0; i < a.Length; i++)
{
a[i] = Convert.ToInt32(Console.ReadLine());
}
int Result = gyrating(a);
if (Result == 1)
{
Console.WriteLine("it is A Gyrating number");
}
else
{
Console.WriteLine("Not A gyrating number");
}
Console.ReadLine();
}
public static int gyrating(int[] input)
{
int rem = 0;
List<int> li = new List<int>();
List<int> li1 = new List<int>();
for (int i = 0; i < input.Length; i++)
{
rem = input[i] % 10;
li.Add(rem);
input[i] = input[i] / 10;
}
for (int j = 0; j < li.Count - 1; j++)
{
if (li[j] < li[j + 1])
li1.Add(0);
else
li1.Add(1);
}
int flag = 1;
for (int j = 0; j < li1.Count - 1; j++)
{
if (li1[j] == li1[j + 1])
{
flag = 2;
break;
}
}
if (flag == 1)
return 1;
//Console.WriteLine("Gyrating");
else
return -1;//Console.WriteLine("Not Gyrating");

}
}
}
////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////
//19)no of days of a month

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
class a
{
//no of days as per month
public static int getnumberofdays(int month, int year)
{
switch (month)
{
case 0: return 31;
case 1: if (((year % 4 == 0) && (year % 100 != 0)) || (year % 400 ==
0))
return 29;
else
return 28;
case 2: return 31;
case 3: return 30;
case 4: return 31;
case 5: return 30;
case 6: return 31;
case 7: return 31;
case 8: return 30;
case 9: return 31;
case 10: return 30;
case 11: return 31;
default: return 0;
}
}
static void Main(string[] args)
{
int m = Convert.ToInt32(Console.ReadLine());
int y = Convert.ToInt32(Console.ReadLine());
int result = getnumberofdays(m, y);
Console.WriteLine(result);
Console.ReadLine();
}
}

////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////

//20)power of the numbers in a integer array


// i/p : 1,2,3,4,5
//o/p:1^0+2^1+3^2+4^3+5^4

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace chap6
{
class Program
{
public static int AddPower(int[] input1)
{
double sum = 0.00;
int result = 0;
for (int i = 0; i < input1.Length; i++)
{
sum = sum + Math.Pow(input1[i], i);

}
result = Convert.ToInt32(sum);
return result;
}
static void Main(string[] args)
{
int[] a = { 1, 5, 7, 9 };
int result = AddPower(a);
Console.WriteLine(result);
Console.ReadLine();
}
}
}
////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////
//21)Roman to decimal
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace RomanToDecimal
{
class Program
{
static void Main(string[] args)
{
string s = Console.ReadLine().ToUpper();
int result = romantodecimal(s);
Console.WriteLine(result);
Console.ReadLine();
}
public static int romantodecimal(string str)
{
// string str = Console.ReadLine().ToUpper();
Dictionary<int, string> dic = new Dictionary<int, string>()
{
{1,"I"},
{4,"IV"},
{5,"V"},
{9,"IX"},
{10,"X"},
{40,"XL"},
{50,"L"},
{90,"XC"},
{100,"C"},
{400,"CD"},
{500,"D"},
{900,"CM"},
{1000,"M"},
};
int value = 0;
while (str.Length > 0)
{
var match = dic.Last(x => str.StartsWith(x.Value));
value += match.Key;
str = str.Substring(match.Value.Length);
}
return value;
}
}
}

////////////////////////////////////////////////////////////////////////////////
////////////////////////////
//22)Sum of cube of n natural numbers
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
class a
{
public static int sumcube(int range)
{
int sum = 0;
for (int i = 0; i <= range; i++)
{
sum = (sum + i * i * i);
}
return sum;
}
static void Main(string[] args)
{
Console.WriteLine("Enter the range");
int r = Convert.ToInt32(Console.ReadLine());
int result = sumcube(r);
Console.WriteLine(result);
Console.ReadLine();
}
}
////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////
//23)smallest string's length count
//Display the length of the smallest string in given string array
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
class program
{
public static int smalleststring(string[] input)
{
//Array.Sort(input);
int c = input[0].Length;
foreach (var item in input)
{
int n = item.Length;
if (n <= c)//if(n>=c) [for highest length]
{
c = n;
}
}
return c;

}
static void Main(string[] args)
{
int size = Convert.ToInt32(Console.ReadLine());
string[] s = new string[size];
for (int i = 0; i < size; i++)
{
s[i] = Console.ReadLine();
}
int result = smalleststring(s);
Console.WriteLine(result);
Console.ReadLine();
}
}
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////
//24) count all the letters in a string[] array and return the number of letters
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication36
{
class Program
{
static void Main(string[] args)
{
string[] input1 = { "santhu", "minnu", "keerthi" };
int c=0,count = 0;
foreach (string s in input1)
{
char[] ch = s.ToCharArray();
foreach (char i in ch)
{
if (char.IsLetter(i))
{
c++;
}
}
}
if (c > 0)
{
count = count + c;
}
Console.WriteLine(count);
Console.Read();
}
}
}

////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////
//25)// CTS-123 . Keep CTS- as constant and change 123 alone
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
namespace ConsoleApplication5
{
class Program
{
static void Main(string[] args)
{
string input1 = "CTS-123";
int output1 = 0;
Regex reg = new Regex(@"^([CTS]+[-]+([0-9]{3}))$");
if (reg.IsMatch(input1))
{
output1 = 1;
}
else
{
output1 = -1;
}
Console.WriteLine(output1);
Console.Read();

}
}
}

////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////
//26)
//append 0 end of a integer array (int[]) where 2nd input is a integer,if in the
integer array contains that 2nd input,dn append 0 in end.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication49
{
class Class14
{
static void Main(string[] args)
{
Console.WriteLine(" Enter the size of the array");
int n = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Enter the array");
int []a=new int[n];
for (int i = 0; i < a.Length; i++)
{
a[i]=Convert.ToInt32(Console.ReadLine());
}
Console.WriteLine("enter the position");
int d=Convert.ToInt32(Console.ReadLine());
int[] r = Find(a,d);
for (int i = 0; i < r.Length; i++)
{
Console.WriteLine(r[i]);
}
Console.ReadLine();
}
public static int[] Find(int[] a, int d)
{
List<int> li = new List<int>();
int c=0;

for (int i = 0; i < a.Length; i++)


{
if (a[i] == d)
{
c++;
}
else
{
li.Add(a[i]);
}
}
for (int i = 0; i <c; i++)
{
li.Add(0);
}
int[] b = li.ToArray();
return b;
}
}
}
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////
//27)
//i/p:cancel policy
//o/p:canel policyc
class program
{
public static string func(string k)
{
string v= k;
string n=v.ToLower();
char[] ch = (from s in n group s by s into g orderby g.Count() desce
nding select g.Key).ToArray();
char s1 = ch[0];
char s2 = char.ToUpper(ch[0]);
char[] c1 = (from n1 in v where n1 == s1 select n1).ToArray();
char[] c2 = (from n2 in v where n2 == s2 select n2).ToArray();
char[] c3 = (from n3 in v where n3 != s1 && n3 != s2 select n3).ToAr
ray();
string v1 = new string(c1);
string v2 = new string(c2);
string v3 = new string(c3);
string v4 = v2 + v3 + v1;
return v4;
}
static void Main(string[] args)
{
string s = "Cancel Policy";
Console.WriteLine(func(s));
Console.ReadKey();
}
}
////////////////////////////////////////////////////////////////////////////////
//////////////////////////////
//28)
//check the sum of two numbers in an array is present in that array then count t
hat
//i/p:1,2,3,5,8,6
//o/p:2 (2+3 = 5 5+3 = 8)

class Program
{
public static int xy(int[] a)
{
int c = 0;
int i = 0, j = 0,sum=0;
for (i = 0; i < a.Length; i++)
{
for (j = i+1; j < a.Length-1; j++)
{
sum = a[i] + a[j];
if(a.Contains(sum))
c++;
}
}
return c;
}
static void Main(string[] args)
{
int[] n1 = { 1, 2, 3, 5, 8,6 };
Console.WriteLine(string.Join(" ",xy(n1)));
Console.ReadKey();
}
}
////////////////////////////////////////////////////////////////////////////////
///////
//29)
//take a input string and an integer and output will be the append string's
//part from that integer input and that number of time

public static string xy(string a, int n)


{
int i = 0;
StringBuilder sb = new StringBuilder();
StringBuilder sb1 = new StringBuilder();
sb1.Append(a);
string h = a.Substring(a.Length - n, n);
for(i=0;i<n;i++)
{
sb.Append(h);
}
sb1.Append(sb);
string k=sb1.ToString();
return k;

}
static void Main(string[] args)
{
string s1 = "cognizant";
int n=3;
Console.WriteLine(xy(s1,n));
Console.ReadKey();
}
}
///////////////////////////

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Cognizant
{
class Class1
{
public static string fun(string str, int i1)
{
string str1 = str.Substring(str.Length - i1);
string res = "";
for (int i = 0; i < i1 - 1; i++)
{
res += str1;
}
string res1 = str + res;
return res1;
}
static void Main(string[] args)
{
string i = Console.ReadLine();
int j = Convert.ToInt32(Console.ReadLine());
string res = fun(i, j);
Console.WriteLine(res);
Console.ReadLine();
}
}
}
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////
//30) consecutive same element three times in a string
public static string xyz(string a)
{
StringBuilder ab = new StringBuilder();
int i = 0, c = 0;
for (i = 0; i < a.Length - 2; i++)
{
c = 0;
if (a[i] == a[i + 1] && a[i + 1] == a[i + 2])
{

c++;
}
if (c > 0)
{
ab.Append(a[i]);
}
else
{
}
}
string s = ab.ToString();
return s;
}

static void Main(string[] args)


{
string a;
a=Console.ReadLine();
Console.WriteLine(xyz(a));
Console.ReadKey();
}
}

}
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////

//31)//count the occurance number of a repeated element in a string


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
class Program
{
public static List<int> fun(int[] a, int n1)
{
List<int> ans = new List<int>();
int f = 0;
foreach (int b in a)
{
if (Array.LastIndexOf(a, b) != Array.IndexOf(a, b))
{
f = Array.LastIndexOf(a, b) - Array.IndexOf(a, b) + 1;
}
}
ans.Add(f);
return ans;
}
static void Main(string[] args)
{
int n1, i;
n1 = Convert.ToInt32(Console.ReadLine());
int[] a = new int[n1];
for (i = 0; i < n1; i++)
{
a[i] = Convert.ToInt32(Console.ReadLine());
}
List<int> li = fun(a, n1);
foreach (var item in li)
{
Console.WriteLine(item);
}

Console.ReadKey();
}
}

////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////
//32)i/p:dog
//o/p:god
class Program
{
public List<string> permutatn(string s)
{
List<string> l = new List<string>();
int f0 = 0, f1 = 1, f2 = 2;
char[] a = s.ToCharArray();
char[] b = new char[a.Length];
for (int i = 0; i < (a.Length*(a.Length-1))/2; i++)
{
b[0] = a[f0];
b[1] = a[f1];
b[2] = a[f2];
string abc = new string(b);
Array.Reverse(b);
string abcd = new string(b);
l.Add(abc);
l.Add(abcd);
f1 = f2;
f2 = f0;
f0 = f0 + 1;
}
return l;
}
static void Main(string[] args)
{
Program p = new Program();
string s = Console.ReadLine();
List<string> li = p.permutatn(s);
foreach(var i in li)
{
Console.WriteLine(i);
}
Console.ReadLine();
}
}
}
////////////////////////////////////////////////////////////////////////////////
/////////
//33) take two strings return the element which is present in maximum time in 2n
d string and common between two strings..
//i/p: s1= I am Boy
//s2= I am good, i am indian
//o/p: i am

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
//to count the maximum no of word present in second string
class a
{
public static string xy(string s1, string s2)
{
StringBuilder sb = new StringBuilder();
string n = "";
int c = 0, max = 0;
int i = 0, j = 0;
char[] ch = { ' ' };
string[] s3 = s1.Split(ch, StringSplitOptions.RemoveEmptyEntries);
char[] ch1 = { ' ' };
string[] s4 = s2.Split(ch1, StringSplitOptions.RemoveEmptyEntries);
for (i = 0; i < s3.Length; i++)
{
c = 0;
for (j = 0; j < s4.Length; j++)
{
if (s3[i] == s4[j])
{
c++;
}
}
if (c > max)
{
n= sb.Append(s3[i]).ToString();
}
}
return n;

static void Main(string[] args)


{
string a = "i am boy";
string b = "i am good and i am indian";
Console.WriteLine(xy(a, b));
Console.ReadKey();
}
}
////////////////////////////////////////////////////////////////////////////////
////////////////////////////
//34)/*
Take two strings from user which can be seperated by space.
* Find how many times the words of second string is present in the first string
.
If any two words in the first string are same then return -1.
* input1 :- "i am indian". input2 :- "i am bengali and also I am indian".
* output:- 5
*/
using System;
using System.Collections.Generic;
class UserProgramCode
{
public static int calcFrequency(string input1, string input2)
{
input1 = input1.ToLower();
input2 = input2.ToLower();
string[] s = input2.Split(' ');
string[] s1 = input1.Split(' ');
List<string> occurrence = new List<string>();
List<string> li = new List<string>();
int c = 0;
int flag = 0;
foreach (var item in s1)
{
if (!li.Contains(item))
{
li.Add(item);
}
else
{
flag++;
return -1;
}
}
foreach (var item in s1)
{
if (Array.IndexOf(s1, item) == Array.LastIndexOf(s1, item))
{
occurrence.Add(item);
}
}
foreach (var item in s)
{
if (occurrence.Contains(item))
{
c++;
}
}
return c;
}

}
class Program
{
public static void Main(string[] args)
{
string input1, input2;
int output = 0;
input1 = Console.ReadLine();
input2 = Console.ReadLine();
output = UserProgramCode.calcFrequency(input1, input2);
Console.WriteLine(output);
Console.ReadLine();
}
}
////////////////////////////////////////////////////////////////////////////////
////////////
//35)using System;
using System.Collections.Generic;
using System.Linq;
/*
* {1,2,3}
{41,25,63}
{64,27,44}
{46,72,44}

1. if length of arrays are not same print -1.


1. if any array have negative print -2.
*/
class UserProgramCode
{
public static int[] CompareArrays(int[] input1, int[] input2)
{
List<int> li = new List<int>();
List<char> li2 = new List<char>();
int[] a = { -1 };
int[] b = { -2 };
Array.Reverse(input2);
if (input1.Length == input2.Length)
{
for (int i = 0; i < input1.Length; i++)
{

if (input1[i] > 0 && input2[i] > 0)


{
li.Add(input1[i] + input2[i]);
}
if (input1[i] < 0 || input2[i] < 0)
{
return b;
}
}

int[] r = li.ToArray();
for (int i = 0; i < r.Length; i++)
{
string s = r[i].ToString();
char[] ch = s.ToCharArray();
Array.Reverse(ch);
s = new string(ch);
r[i] = Convert.ToInt32(s);
}
return r;
}
else
{
return a;
}
}
}

class Program
{
static void Main(string[] args)
{
int size1, size2;
Console.WriteLine("Enter first array size");
size1 = Convert.ToInt32(Console.ReadLine());
int[] arr1 = new int[size1];
Console.WriteLine("Enter array elements");
for (int i = 0; i < size1; i++)
{
arr1[i] = Convert.ToInt32(Console.ReadLine());
}
Console.WriteLine("Enter second array size");
size2 = Convert.ToInt32(Console.ReadLine());
int[] arr2 = new int[size2];
Console.WriteLine("Enter array elements");
for (int i = 0; i < size2; i++)
{
arr2[i] = Convert.ToInt32(Console.ReadLine());
}
int[] output = UserProgramCode.CompareArrays(arr1, arr2);
//for (int i = 0; i < output.Length; i++)
//{
// Console.WriteLine(output[i]);
//}
for (int i = 0; i < output.Length; i++)
{
if (output[i] == -1)
{
Console.WriteLine("length is not equal");
}
else if (output[i] == -2)
{
Console.WriteLine("there is negative number");
}
else
Console.WriteLine(output[i]);
}

Console.ReadLine();
}
}
////////////////////////////////////////////////////////////////////////////////
////////////////////
//36)take three strings if 2nd and thrd string is present then business logics w
ith their orders
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
class program
{
public static int stringmatch(string input1, string input2, string input3)
{
char[] ch = input1.ToCharArray();
int a = input1.IndexOf(input2);
int b = input1.IndexOf(input3);
if (a == b)
{
return 2;
}
else if (a != b)
{
if (a < b)
{
return 1;
}
else
{
return 3;
}
}
else if (a <0)
{
return -1;
}
else if (b <0)
{
return -2;
}
else
{
return -3;
}
}
static void Main(string[] args)
{
string a = "I am a good boy";
string b= "i ";
string c = "";
int result = stringmatch(a, b, c);
Console.WriteLine(result);
Console.ReadLine();
}
}

////////////////////////////////////////////////////////////////////////////////
//////////////////
//37)if there is sqare then insert cube and if there is cube then square
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ArraySquareThenInsertCube
{
class a
{
public static int[] check(int[] n, int a)
{
List<int> list = new List<int>();
int i;
for (i = 0; i < a - 1; i++)
{
list.Add(n[i]);
if (n[i] * n[i] == n[i + 1])
{
int num = n[i] * n[i] * n[i];
list.Add(num);
}
else if (n[i] * n[i] * n[i] == n[i + 1])
{
int num = n[i] * n[i];
list.Add(num);
}
if (n[i] < 0)
{
int num = n[i] * n[i];
list.Add(num);
}
}

list.Add(n[n.Length - 1]);

n = list.ToArray();
return n;
}
static void Main(string[] args)
{
int[] input2 = { 1, 2, 8, 64, 7, 5, 6 };
int[] we = check(input2, 7);
for (int i = 0; i < we.Length; i++)
{
Console.WriteLine(we[i]);
}
Console.ReadLine();
}
}
}
////////////////////////////////////////////////////////////////////////////////
////////////
//38) John williams to williams,J
public static string xy(string a)
{
StringBuilder sb=new StringBuilder();
char []c1={' '};
string []s1=a.Split(c1,StringSplitOptions.RemoveEmptyEntries);
string k = s1[0];
string v=k.Substring(0,1);
sb.Append(s1[1]);
sb.Append(',');
sb.Append(v);
string n=sb.ToString();
return n;
}
static void Main(string[] args)
{
string c = "john williams";
Console.WriteLine(xy(c))
}

////////////////////////////////////////////////////////////////////////////////
//////////////////////
//39)5)i/p-mango,cat,apple
//o/p-apple,mango,cat
//sort by string length then alphabeticaly
class Program
{
public static string xy(string []a)
{
StringBuilder ab = new StringBuilder();
string[] s1 = (from n in a orderby n.Length descending, n select n).
ToArray();
foreach (var v in s1)
{
ab.Append(v);
ab.Append(" ");
}
string k = ab.ToString();
return k;
//string.Join(" ", s1);

}
////////////////////////////////////////////////////////////////////////////////
/////
//40)//match the string length split by charecters like '-'

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
class Program
{
public static string xy(string a, string b)
{
int c = 0, n3 = 0;
int n1 = (from s in a where s.Equals('-') select s).Count();
int n2 = (from s1 in b where s1.Equals('-') select s1).Count();
if (n1 == n2)
{
c++;
}
if (c > 0 && a.IndexOf('-') == b.IndexOf('-'))
{
n3++;
}
if (n3 > 0)
return "1";
else
return "-1";

}
static void Main(string[] args)
{
string s1 = "acvf-g-kji";
string s2 = "jllg-i-jhj";
Console.WriteLine(xy(s1, s2));
Console.ReadKey();
}
}
/////////////////////////////////////////////////////////////////
//41)2)difference between maximum and minimum number.
public static int xyz(int[] a,int c)
{
int n1 = (from s in a select s).Max();
int n2 = (from s1 in a select s1).Min();
int n3 = n1 - n2;
return n3;
}
static void Main(string[] args)
{
int n1,i=0;
Console.WriteLine("enter");
n1 = Convert.ToInt32(Console.ReadLine());
int []n2=new int [n1];
for (i = 0; i < n1; i++)
{
n2[i]=Convert.ToInt32(Console.ReadLine());
}
Console.WriteLine(xyz(n2,n1));
Console.ReadKey();
}
}
}
//..........................or........................
//max difference between elements of array:
class Program
{
static void Main(string[] args)
{
int size = Convert.ToInt32(Console.ReadLine());
int[] arr = new int[size];
for (int i = 0; i < size; i++)
arr[i] = Convert.ToInt32(Console.ReadLine());
Console.WriteLine(UserProgramCode.getMaxSpan(size, arr));
Console.ReadLine();
}
}
class UserProgramCode
{
public static int getMaxSpan(int size, int[] arr)
{
//Fill your code here
int n = arr.Max();
int p = arr.Min();
int s = n - p;
return s;

}
}
////////////////////////////////////////////////////////////////////////////////
//42)Max span in an array
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace LagestPalindromeInaString
{
class Program
{
static void Main(string[] args)
{
int n = int.Parse(Console.ReadLine());
int[] nums = new int[n];
for (int i = 0; i < n; i++)
{
nums[i] = int.Parse(Console.ReadLine());
}
int output = maxSpan(nums);
Console.WriteLine(output);
}
public static int maxSpan(int[] nums)
{
int count = 1;
int maxspan = 0;
for (int i = 0; i < nums.Length; i++)
{
for (int j = i + 1; j < nums.Length; j++)
{
if (nums[i] == nums[j])
{
count++;
maxspan = count;
int number = nums[i];
}
}
}
return maxspan;
}
}
}
////////////////////////////////////////////////////////////////////////////////
//
//43) LCM of numbers in an array
ip= 2 5 8
op= 40
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace StringRepeatation
{
class Program
{
static void Main(string[] args)
{
int n = int.Parse(Console.ReadLine());
int[] input = new int[n];
for (int i = 0; i < n; i++)
{
input[i] = int.Parse(Console.ReadLine());
}
int output = 0;
int max = input.Max();
while (max != 0)
{
int count = 0;
for (int i = 0; i < n; i++)
{
if (max % input[i] == 0)
{
count++;
}
}
if (count == n)
{
output = max;
break;
}
else
{
max++;
}
}
Console.WriteLine(output);
}
}
}
////////////////////////////////////////////////////////////////////////////////
///////////////////
//44)gcd........
using System;
using System.Linq;
public class Program
{
static void Main()
{
Console.WriteLine(CalculateGCD(new[] { 10, 2 }));
Console.ReadLine();
}
static int CalculateGCD(int[] numbers)
{
return numbers.Aggregate(GCD);
}
static int GCD(int a, int b)
{
return b == 0 ? a : GCD(b, a % b);
}
}
//////////////////////////////////////////////////////////////////
//45)86. find and print values from list greater than input value:
ip=1 2 3 4 5
ip2=3
op=4 5

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ListFetch
{
class Program
{
public static List<int> FindNumber(List<int> list, int ip)
{
List<int> list1 = new List<int>();
for (int i = 0; i < list.Count; i++)
{
if (list[i] > ip)
{
list1.Add(list[i]);
}
}
return list1;
}

static void Main(string[] args)


{
Console.WriteLine("How many digit you want to entered?");
int n = int.Parse(Console.ReadLine());
List<int> list = new List<int>();
Console.WriteLine("Enter the values:");
for (int i = 0; i < n; i++)
{
list.Add(int.Parse(Console.ReadLine()));
}
Console.WriteLine("Enter the min number");
int ip = int.Parse(Console.ReadLine());
List<int> list1 = FindNumber(list,ip);
Console.WriteLine("Current list contains:");
for (int i = 0; i < list1.Count; i++)
{
Console.WriteLine(list1[i]);
}
}
}
}
////////////////////////////////////////////////////////////////////////////////
/////////////////////
//46). Average of max and min value
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace q1
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Enter the range:");
int n = Convert.ToInt32(Console.ReadLine());
int[] arr = new int[n];
for (int i = 0; i < n; i++)
{
arr[i] = Convert.ToInt32(Console.ReadLine());
}
int max = arr[0];
int min = arr[0];
for (int i = 0; i < n; i++)
{
if (arr[i] > max)
{
max = arr[i];
}
if (arr[i] < min)
{
min = arr[i];
}
}
double average = Convert.ToDouble((max + min) / 2);
Console.WriteLine("Average={0}", average);
}
}
}
////////////////////////////////////////////////////////////////////////////////
///////////////////////
//47) input:66.45 output : ((6+6).(4+5))=12.9
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace dtyghgujh
{
class Program
{
static void Main(string[] args)
{
double sum = 0, sum1 = 0;
string s = "22.67";
string[] t = s.Split('.');
int n1 = Convert.ToInt32(t[0]);
int n2 = Convert.ToInt32(t[1]);
while (n1 > 0)
{
int temp = n1 % 10;
sum = sum + temp;
n1 = n1 / 10;
}
while (n2 > 0)
{
int temp1 = n2 % 10;
sum1 = sum1 + temp1;
n2 = n2 / 10;
}
string SD = sum + "." + sum1;
double result = Convert.ToDouble(SD);
Console.WriteLine(result);
Console.ReadLine();
}
}
}
////////////////////////////////////////////////////////////////////////////////
////////
//48) take an integer array and an iteger as input,if the input integer is prese
nt in array elemnt
//then replace 0 with the element and add it to the last of the array
//i/p: 5,6,8,10,12,10,4,10
//i/p:10
//o/p:5,6,8,12,4,0,0,0

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication49
{
class Class14
{
static void Main(string[] args)
{
Console.WriteLine(" Enter the size of the array");
int n = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Enter the array");
int []a=new int[n];
for (int i = 0; i < a.Length; i++)
{
a[i]=Convert.ToInt32(Console.ReadLine());
}
Console.WriteLine("enter the position");
int d=Convert.ToInt32(Console.ReadLine());
int[] r = Find(a,d);
for (int i = 0; i < r.Length; i++)
{
Console.WriteLine(r[i]);
}
Console.ReadLine();
}
public static int[] Find(int[] a, int d)
{
List<int> li = new List<int>();
int c=0;

for (int i = 0; i < a.Length; i++)


{
if (a[i] == d)
{
c++;
}
else
{
li.Add(a[i]);
}
}
for (int i = 0; i <c; i++)
{
li.Add(0);
}
int[] b = li.ToArray();
return b;
}
}
}
////////////////////////////////////////////////////////////////////////////////
////////////////////////
49)Change the nth element in the given string to *
Intput1=Hi Are You Fine Ram
Input2=5
Input3=hi are you fine ***(it shld b in lower)
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication5
{
class Program
{
static void Main(string[] args)
{
string input1 = "hi how are you ram";
string[] str1 = input1.Split(' ');
int input2 = 5;
int len = str1[input2-1].Length;
StringBuilder sb = new StringBuilder();
StringBuilder sb1 = new StringBuilder();
for (int i = 0; i < len; i++)
{
sb.Append('*');
}
str1[input2-1] = sb.ToString();
for (int i = 0; i < str1.Length; i++)
{
sb1.Append(str1[i]);
sb1.Append(' ');

}
Console.WriteLine(sb1.ToString().TrimEnd());
Console.ReadLine();
}
}
}
////////////////////////////////////////////////////////////////////////////////
/////////////////////
50)i/p:Cancel Policy
o/p:Canel Policyc

public static string func(string k)


{
string v= k;
string n=v.ToLower();
char[] ch = (from s in n group s by s into g orderby g.Count() desce
nding select g.Key).ToArray();
char s1 = ch[0];
char s2 = char.ToUpper(ch[0]);
char[] c1 = (from n1 in v where n1 == s1 select n1).ToArray();
char[] c2 = (from n2 in v where n2 == s2 select n2).ToArray();
char[] c3 = (from n3 in v where n3 != s1 && n3 != s2 select n3).ToAr
ray();
string v1 = new string(c1);
string v2 = new string(c2);
string v3 = new string(c3);
string v4 = v2 + v3 + v1;
return v4;
}
static void Main(string[] args)
{
string s = "Cancel Policy";
Console.WriteLine(func(s));
Console.ReadKey();
}
}
-----------------------------or-------------------------------------------------
----------------------
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication4
{
class Program
{
static void Main(string[] args)
{
string s = Console.ReadLine();
string s2 = " ";
int k, max = 0, flag = 0, x = 0;
int[] a = new int[20];
int[] b = new int[20];
char[] c5 = s.ToCharArray();
for (int z = 0; z < c5.Length; z++)
{
if (char.IsLower(c5[z]))
{
}
else
{
flag++;
}
}
if (flag > 0)
{

char[] c = s.ToCharArray();
for (int i = 0; i < c.Length; i++)
{
char ch = char.ToLower(c[i]);
k = 1;
for (int j = i + 1; j < (c.Length); j++)
{
char ch1 = char.ToLower(c[j]);
if (ch == ch1)
{
k++;
}
}
a[i] = k;
b[i] = k;
}
Array.Resize(ref a, c.Length);
Array.Resize(ref b, c.Length);
Array.Sort(b);
max = b[c.Length - 1];

if (b[c.Length - 2] == b[c.Length - 1])


{
s2 = "not possible";
}
else
{
int y = 0;
while (a[y] != max)
y++;

char c1 = c[y];
char c6 = char.ToLower(c1);
StringBuilder sb = new StringBuilder();
char c2 = char.ToUpper(c6);
foreach (char c3 in c5)
{
if (c2 == c3)
x++;
}

for (int f = 0; f < x; f++)


sb.Append(c2);
for (int m = 1; m < c.Length; m++)
{
if ((c[m] != c6) && (c[m] != c2))
sb.Append(c[m]);
else
{
}
}
for (int n = 0; n < max - x; n++)
sb.Append(c6);
s2 = sb.ToString();

}
}
else
s2 = "condition not met";
Console.WriteLine(s2);
Console.ReadLine();
}
}
}
////////////////////////////////////////////////////////////////////////////////
//////////////////////////
51)
ip= CyclePolicy
op= CylePoliycc
Highest frequency come front(Upper Case) & goes last(lower Case)..
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication4
{
class Program
{
static void Main(string[] args)
{
string s = Console.ReadLine();
string s2 = " ";
int k, max=0,flag=0,x=0;
int[] a = new int[20];
int[] b = new int[20];
char[] c5 = s.ToCharArray();
for (int z = 0; z < c5.Length; z++)
{
if (char.IsLower(c5[z]))
{
}
else
{
flag++;
}
}
if (flag > 0)
{

char[] c = s.ToCharArray();
for (int i = 0; i < c.Length; i++)
{
char ch = char.ToLower(c[i]);
k = 1;
for (int j = i + 1; j < (c.Length); j++)
{
char ch1 = char.ToLower(c[j]);
if (ch == ch1)
{
k++;
}
}
a[i] = k;
b[i] = k;
}
Array.Resize(ref a, c.Length);
Array.Resize(ref b, c.Length);
Array.Sort(b);

max = b[c.Length - 1];

if (b[c.Length - 2] == b[c.Length - 1])


{
s2 = "not possible";
}
else
{
int y = 0;
while (a[y] != max)
y++;

char c1 = c[y];
char c6 = char.ToLower(c1);
StringBuilder sb = new StringBuilder();
char c2 = char.ToUpper(c6);
foreach (char c3 in c5)
{
if (c2 == c3)
x++;
}

for (int f = 0; f < x; f++)


sb.Append(c2);
for (int m = 1; m < c.Length; m++)
{
if ((c[m] != c6) && (c[m]!=c2))
sb.Append(c[m]);
else
{
}
}
for (int n = 0; n < max - x; n++)
sb.Append(c6);
s2 = sb.ToString();

}
}
else
s2 = "condition not met";
Console.WriteLine(s2);
}
}
}

////////////////////////////////////////////////////////////////////////////////
////////////////

52)check if the sum two elements present in that array,if present then return th
e count of those elements
i/p:1,2,3,4,5,8,6
o/p:3
logic:(1+2=3,2+3=5,5+3=8)

class Program
{
public static int xy(int[] a)
{
int c = 0;
int i = 0, j = 0,sum=0;
for (i = 0; i < a.Length; i++)
{
for (j = i+1; j < a.Length-1; j++)
{
sum = a[i] + a[j];
if(a.Contains(sum))
c++;
}
}
return c;
}
static void Main(string[] args)
{
int[] n1 = { 1, 2, 3, 5, 8,6 };
Console.WriteLine(string.Join(" ",xy(n1)));
Console.ReadKey();
}
}
////////////////////////////////////////////////////////////////////////////////
///////////////////////////
53)//take a input string and an integer and output will be the append string's
//part from that integer input and that number of time
i/p:Cognizant
i/p:3
o/p:Cognizantantant
public static string xy(string a, int n)
{
int i = 0;
StringBuilder sb = new StringBuilder();
StringBuilder sb1 = new StringBuilder();
sb1.Append(a);
string h = a.Substring(a.Length - n, n);
for(i=0;i<n;i++)
{
sb.Append(h);
}
sb1.Append(sb);
string k=sb1.ToString();
return k;

}
static void Main(string[] args)
{
string s1 = "cognizant";
int n=3;
Console.WriteLine(xy(s1,n));
Console.ReadKey();
}
}
................................or...........................................

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Cognizant
{
class Class1
{
public static string fun(string str, int i1)
{
string str1 = str.Substring(str.Length - i1);
string res = "";
for (int i = 0; i < i1 - 1; i++)
{
res += str1;
}
string res1 = str + res;
return res1;
}
static void Main(string[] args)
{
string i = Console.ReadLine();
int j = Convert.ToInt32(Console.ReadLine());
string res = fun(i, j);
Console.WriteLine(res);
Console.ReadLine();
}
}
}
////////////////////////////////////////////////////////////////////////////////
///////////////////////////
54)Concat a string from a string arrays every string's 2nd(user input) charecter
i/p: abc,acd,adf,afg
i/p:2
o/p:bcdf

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
class Program
{
static void Main(string[] args)
{
string op = " ";
Console.WriteLine("enter the size");
int n = Convert.ToInt32(Console.ReadLine());
StringBuilder sb=new StringBuilder();
string[] s = new string[10];
for (int i = 0; i < n; i++)
{
s[i]=Console.ReadLine();
}
for (int i = 0; i < n;i++)
{
if (s[i].Length == 1)
{
op = "-1";
Console.WriteLine(op);
break;
}
}
foreach (string str in s)
{
if(!string.IsNullOrEmpty(str))
{
foreach (char c in str)
{
if (char.IsDigit(c))
{
op = "-2";
Console.WriteLine(op);
break;
}
else if (!char.IsLetterOrDigit(c))
{
op = "-3";
Console.WriteLine(op);
break;
}
else
{
sb.Append(str.Substring(1,1).ToString());
break;
}
}
}
}
op = sb.ToString();
Console.WriteLine(op);
Console.ReadLine();
}
}
////////////////////////////////////////////////////////////////////////////////
///////////////////////////
55)consecutive three elements in a string

public static string xyz(string a)


{
StringBuilder ab = new StringBuilder();
int i = 0, c = 0;
for (i = 0; i < a.Length - 2; i++)
{
c = 0;
if (a[i] == a[i + 1] && a[i + 1] == a[i + 2])
{

c++;
}
if (c > 0)
{
ab.Append(a[i]);
}
else
{
}
}
string s = ab.ToString();
return s;
}

static void Main(string[] args)


{
string a;
a=Console.ReadLine();
Console.WriteLine(xyz(a));
Console.ReadKey();
}
}

}
////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////

56)//you have to take a string and one character .you have to find how many time
s the character is present in the string.
//it will not have any special character/numbers.
//the o/p will return the count and if no/characters are there then it will show
invalid i/p

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

class a
{
static void Main(string[] args)
{
string i = Console.ReadLine();
char a = Convert.ToChar(Console.ReadLine());
int result = countchar(i, a);
if (result == 0)
{
Console.WriteLine("Invalid Input");
}
else
{
Console.WriteLine(result);
}
Console.ReadLine();
}
public static int countchar(string input, char c)
{
int count = 0;
char[] a = input.ToCharArray();
for (int i = 0; i < a.Length; i++)
{
if (a[i] == c)
{
count++;
}
}
//for (int i = 0; i < a.Length; i++)
//{
// if (char.IsDigit(a[i]) || char.IsSymbol(a[i]))
// {
// return -1;
// }
//}
return count;
}
}
////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////

57)//2.you have to take two strings.you have to check how many times the second
element of the 2nd string is present in the first string.
//if present print the count else print -1;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
class a
{
static void Main(string[] args)
{
string a = Console.ReadLine();
string b = Console.ReadLine();
int result = count(a, b);
Console.WriteLine(result);
Console.ReadKey();

}
public static int count(string input1, string input2)
{
int count = 0;
string[] b = input1.Split(' ');
string[] c = input2.Split(' ');
string s = c[1];
for (int i = 0; i < b.Length; i++)
{
if (c[1] == b[i])
{
count++;
}

}
return count;
}
}

////////////////////////////////////////////////////////////////////////////////
/////////////////////////////
58)count the occurace of a repeatated element in list integer type
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
class Program
{
public static List<int> fun(int[] a, int n1)
{
List<int> ans = new List<int>();
int f = 0;
foreach (int b in a)
{
if (Array.LastIndexOf(a, b) != Array.IndexOf(a, b))
{
f = Array.LastIndexOf(a, b) - Array.IndexOf(a, b) + 1;
}
}
ans.Add(f);
return ans;
}
static void Main(string[] args)
{
int n1, i;
n1 = Convert.ToInt32(Console.ReadLine());
int[] a = new int[n1];
for (i = 0; i < n1; i++)
{
a[i] = Convert.ToInt32(Console.ReadLine());
}
List<int> li = fun(a, n1);
foreach (var item in li)
{
Console.WriteLine(item);
}
Console.ReadKey();
}
}
////////////////////////////////////////////////////////////////////////////////
//////////////////////////////

59) i/p:dog
o/p:god
class Program
{
public List<string> permutatn(string s)
{
List<string> l = new List<string>();
int f0 = 0, f1 = 1, f2 = 2;
char[] a = s.ToCharArray();
char[] b = new char[a.Length];
for (int i = 0; i < (a.Length*(a.Length-1))/2; i++)
{
b[0] = a[f0];
b[1] = a[f1];
b[2] = a[f2];
string abc = new string(b);
Array.Reverse(b);
string abcd = new string(b);
l.Add(abc);
l.Add(abcd);
f1 = f2;
f2 = f0;
f0 = f0 + 1;
}
return l;
}
static void Main(string[] args)
{
Program p = new Program();
string s = Console.ReadLine();
List<string> li = p.permutatn(s);
foreach(var i in li)
{
Console.WriteLine(i);
}
Console.ReadLine();
}
}
}
////////////////////////////////////////////////////////////////////////////////
///////////////////
60//email address verification

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
namespace ConsoleApplication85
{
class Program
{
static void Main(string[] args)
{
string i = Console.ReadLine();
int result = fun1(i);
Console.WriteLine(result);
Console.ReadLine();
}

public static int fun1(string email)


{
int out1 = 0;
Regex reg = new Regex("([A-Za-z0-9._]+[@]+[A-Za-z]+[.]+[A-Za-z])");
if (reg.IsMatch(email))
{
out1 = 1;
}
else
out1 = -1;
return out1;

}
}
}
////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////
61)ip address verification

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Mam
{
class Class1
{
public static int fun(string str)
{
int f = 0,out1=0;
string[] word = str.Split('.');
foreach (string s in word)
{
foreach (char c in s)
{
if (char.IsDigit(c) || c == '.')
{
f = 1;
}
else
f = -1;
}
if (f == 1)
{
if (word.Length == 4 && word[0].Length == 3 && Convert.ToInt
32(word[0]) > 0 && Convert.ToInt32(word[0]) <= 255 && word[1].Length == 3
&& Convert.ToInt32(word[1]) >= 1 && Convert.ToInt32(word[0])
<= 255 && word[2].Length == 3 && Convert.ToInt32(word[2]) >= 1 &&
Convert.ToInt32(word[2]) <= 255 && word[3].Length == 3 && Co
nvert.ToInt32(word[3]) >= 1 && Convert.ToInt32(word[3]) <= 255)
{
out1 = 1;
}
else
out1 = -1;
}
}
return out1;
}
}
}
////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////
62)CTS-HYD-12345
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
class a
{
static void Main(string[] args)
{
string a = Console.ReadLine();
string b = Console.ReadLine();
int res = cts(a, b);
Console.WriteLine(res);
Console.ReadLine();
}
public static int cts(string input1, string input2)
{
int output = 0;
Regex reg = new Regex(@"^([CTS]+[-]+([a-zA-Z]{3})+[-]+([0-9]{4}))$");
if (reg.IsMatch(input1))
{
string res = input2.ToUpper();
if (input1.Contains(input2.Substring(0, 3)))
{
output = 1;
}
else
{
output = -1;
}
}
else
output = -2;
return output;
}
}
////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////

63)password verification
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication124
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("enter the password");
string pw = Console.ReadLine();
int c = passwordcheck(pw);
if (c > 0)
{
Console.WriteLine("true");
}
if (c == 0)
{
Console.WriteLine("false");
}
Console.ReadLine();
}
static int passwordcheck(string ss)
{
int c = 0;
int flag1 = 0;
int flag2 = 0;
int flag3 = 0;
int flag4 = 0;
if ( ss.Length >= 8 && ss.Length <= 10 )
{
char[] ch = ss.ToCharArray();
foreach (var item in ch)
{
if (char.IsSymbol(item) || char.IsPunctuation(item))
{
flag1 = flag1 + 1;
}
if (char.IsUpper(item))
{
flag2 = flag2 + 1;
}
if (char.IsLower(item))
{
flag3 = flag3 + 1;
}
if (char.IsDigit(item))
{
flag4 = flag4 + 1;
}

}
if (flag1 > 0 && flag2 > 0 && flag3 > 0 && flag4 > 0)
{
if ((!char.IsDigit(ch[0])) && (!char.IsPunctuation(ch[0]))
&& (!char.IsSymbol(ch[0])))
{
foreach (var item in ch)
{
if (!char.IsWhiteSpace(item))
{
c = c + 1;
}
}
}
}

}
return (c);
}
}
}
////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////

64) Phone Number Validate::


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
namespace NumberValidation
{
class Program
{
static void Main(string[] args)
{
string num = Console.ReadLine();
int output = 0;
Regex reg = new Regex(@"^[+]+[91]+[-]+([0-9]{3})+[-]+([0-9]{3})+[-]+
([0-9]{4})$");
if (reg.IsMatch(num))
{
if (num.Substring(1, 1) == "9")
output = 1;
else
output = -2;
}
else
output = -1;
Console.WriteLine(output);
}
}
}
.......................
phone number validation
eg:123-123-1111
string s =Console.ReadLine();
Regex re=new Regex(@"([0-9]{3}[-][0-9]{3}[-][0-9]{4})$");
if (re.IsMatch(s))
{
Console.WriteLine("vaild");
}
else
{
Console.WriteLine("invalid");
}
Console.ReadKey();

////////////////////////////////////////////////////////////////////////////
65)Regular expression to check pattern hi-how-are-you

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
namespace ConsoleApplication5
{
class Program
{
static void Main(string[] args)
{
string input1="hi-how-are-you";
int output1 = 0;
Regex reg=new Regex(@"^(([a-zA-Z]{2})+[-]+([A-Za-z]{3})+[-]+([a-zA-Z
]{3})+[-]+([a-zA-Z]{3}))$");
if (reg.IsMatch(input1))
{
output1 = 1;
}
else
{
output1 = -1;
}
Console.WriteLine(output1);
Console.Read();

}
}
}
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////
66)color code format checking using regex
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
namespace ConsoleApplication5
{
class Program
{
public static void Main(string[] args)
{
string input1 = "#FF85HH";
int output1 = 0;
Regex reg = new Regex(@"^([#]+([A-Z]{2})+([0-9]{2})+([A-Z]{2}))$");
if (reg.IsMatch(input1))
{
output1 = 1;
}
else
{
output1 = -1;
}
Console.WriteLine(output1);
}
}
}
...............................or......................................
color code format checking using regex
public static void Main(string[] args)
{
string input1 = "#FF85HH";
int output1 = 0;
Regex reg = new Regex(@"^([#])+([A-F0-9]{6})+$");
if (reg.IsMatch(input1))
{
output1 = 1;
}
else
{
output1 = -1;
}
Console.WriteLine(output1);
Console.Read();

////////////////////////////////////////////////////////////////////////////////
//////////////////////
67)//string encription
//i/p:abcd
//i/p:2
//o/p:cdeg
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace EncryptionString
{
class Class3
{
public static string fun3(string input, int x)
{
string out2 = "";
StringBuilder sb = new StringBuilder();
foreach (char c in input)
{
char nextchar = (c == 'Z' ? (char)('A' + (x - 1)) : c == 'z' ? (
char)('a' + (x - 1)) : (char)(c + x));
sb.Append(nextchar);
}
out2 = sb.ToString();
return out2;

}
static void Main(string[] args)
{
string i = Console.ReadLine();
int j = Convert.ToInt32(Console.ReadLine());
string result = fun3(i, j);
Console.WriteLine(result);
Console.ReadLine();
}
}
}

////////////////////////////////////////////////////////////////////////////////
//////////////////////////////

68)Excellent AXE
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication88
{

public class UserMainCode


{
public static string ProcessString(string s)
{
string s1 = "";
StringBuilder sb = new StringBuilder();
StringBuilder sb1 = new StringBuilder();
char[] ch=s.ToCharArray();

for (int i = 0; i < ch.Length; i++)


{
if (ch[i] == 'x')
{
sb.Append(ch[i]);
}
else
sb1.Append(ch[i]);
}
string ss = sb1.ToString();
s1 = ss + sb.ToString();
return s1;

}
static void Main(string[] args)
{
string i = Console.ReadLine();
string j = ProcessString(i);
Console.WriteLine(j);
Console.ReadLine();
}

}
}
////////////////////////////////////////////////////////////////////////////////
/////////////////////

69)//to count the maximum no of word present in second string


i/p: string a = "this is my name";
string b = "this is is name name name ";
o/p: name:3

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

class a
{
public static string xy(string s1, string s2)
{
StringBuilder sb = new StringBuilder();
string n = "";
int c=0,max=0;
int i=0,j=0;
char[] ch = { ' ' };
string[] s3 = s1.Split(ch, StringSplitOptions.RemoveEmptyEntries);
char[] ch1 = { ' ' };
string[] s4 = s2.Split(ch1, StringSplitOptions.RemoveEmptyEntries);
for (i = 0; i < s3.Length; i++)
{
c = 0;
for (j = 0; j < s4.Length; j++)
{
if (s3[i] == s4[j])
{
c++;
}
}
if (c > max)
{
max = c;
n = s3[i];
}
}

return n;
}

static void Main(string[] args)


{
string a = "this is my name";
string b = "this is is name name name ";
Console.WriteLine(xy(a,b));
Console.ReadKey();
}
}

////////////////////////////////////////////////////////////////////////////////
//////////////////////
70)/*
* {1,2,3}
{41,25,63}
{64,27,44}
{46,72,44}

1. if length of arrays are not same print -1.


1. if any array have negative print -2.
*/

using System;
using System.Collections.Generic;
using System.Linq;
class UserProgramCode
{
public static int[] CompareArrays(int[] input1, int[] input2)
{
List<int> li = new List<int>();
List<char> li2 = new List<char>();
int[] a = { -1 };
int[] b = { -2 };
Array.Reverse(input2);
if (input1.Length == input2.Length)
{
for (int i = 0; i < input1.Length; i++)
{

if (input1[i] > 0 && input2[i] > 0)


{
li.Add(input1[i] + input2[i]);
}
if (input1[i] < 0 || input2[i] < 0)
{
return b;
}
}

int[] r = li.ToArray();
for (int i = 0; i < r.Length; i++)
{
string s = r[i].ToString();
char[] ch = s.ToCharArray();
Array.Reverse(ch);
s = new string(ch);
r[i] = Convert.ToInt32(s);
}
return r;
}
else
{
return a;
}

}
}

class Program
{
static void Main(string[] args)
{
int size1, size2;
Console.WriteLine("Enter first array size");
size1 = Convert.ToInt32(Console.ReadLine());
int[] arr1 = new int[size1];
Console.WriteLine("Enter array elements");
for (int i = 0; i < size1; i++)
{
arr1[i] = Convert.ToInt32(Console.ReadLine());
}
Console.WriteLine("Enter second array size");
size2 = Convert.ToInt32(Console.ReadLine());
int[] arr2 = new int[size2];
Console.WriteLine("Enter array elements");
for (int i = 0; i < size2; i++)
{
arr2[i] = Convert.ToInt32(Console.ReadLine());
}
int[] output = UserProgramCode.CompareArrays(arr1, arr2);
//for (int i = 0; i < output.Length; i++)
//{
// Console.WriteLine(output[i]);
//}
for (int i = 0; i < output.Length; i++)
{
if (output[i] == -1)
{
Console.WriteLine("length is not equal");
}
else if (output[i] == -2)
{
Console.WriteLine("there is negative number");
}
else
Console.WriteLine(output[i]);
}

Console.ReadLine();
}
}
////////////////////////////////////////////////////////////////////////////////
///////////////////////
71)check the sequence of two input strings in a 3rd string

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
class program
{
public static int stringmatch(string input1, string input2, string input3)
{
char[] ch = input1.ToCharArray();
int a = input1.IndexOf(input2);
int b = input1.IndexOf(input3);
if (a == b)
{
return 2;
}
else if (a != b)
{
if (a < b)
{
return 1;
}
else
{
return 3;
}
}
else if (a <0)
{
return -1;
}
else if (b <0)
{
return -2;
}
else
{
return -3;
}
}
static void Main(string[] args)
{
string a = "I am a good boy";
string b= "i ";
string c = "";
int result = stringmatch(a, b, c);
Console.WriteLine(result);
Console.ReadLine();
}
}
................or..............................

/*you have to give three strings


str1=Raj Kumar Dev
str2=Raj
str3=Dev
you have to check if the str3 is present after str2.
if yes print 1 else -1*/

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication4
{
class Program
{
static void Main(string[] args)
{
string str1 = "Raj Kumar Dev";
string str2 = "Dev";
string str3 = "Raj";
bool result=sourav(str1,str2,str3);
if(result)
Console.WriteLine(1);
else
Console.WriteLine(-1);
Console.ReadLine();
}
public static bool sourav(string str1,string str2,string str3)
{
string[] s = str1.Split(' ');
if (Array.IndexOf(s, str2) < Array.IndexOf(s, str3))
{
return true;
}
else
{
return false;
}

}
}
}

////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////

72)if ther is square of an eleemnt in the next position then add its cube and vi
se versa
i/p:2,8,5,25,6
o/p:2,4,8,5,125,25,6
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ArraySquareThenInsertCube
{
class a
{
public static int[] check(int[] n, int a)
{
List<int> list = new List<int>();
int i;
for (i = 0; i < a - 1; i++)
{
list.Add(n[i]);
if (n[i] * n[i] == n[i + 1])
{
int num = n[i] * n[i] * n[i];
list.Add(num);
}
else if (n[i] * n[i] * n[i] == n[i + 1])
{
int num = n[i] * n[i];
list.Add(num);
}
if (n[i] < 0)
{
int num = n[i] * n[i];
list.Add(num);
}
}

list.Add(n[n.Length - 1]);

n = list.ToArray();
return n;
}
static void Main(string[] args)
{
int[] input2 = { 1, 2, 8, 64, 7, 5, 6 };
int[] we = check(input2, 7);
for (int i = 0; i < we.Length; i++)
{
Console.WriteLine(we[i]);
}
Console.ReadLine();
}
}
}

///////////////////////////////////////////////////////////////////////////////
73)2)difference between maximum and minimum number.
public static int xyz(int[] a,int c)
{
int n1 = (from s in a select s).Max();
int n2 = (from s1 in a select s1).Min();
int n3 = n1 - n2;
return n3;
}
static void Main(string[] args)
{
int n1,i=0;
Console.WriteLine("enter");
n1 = Convert.ToInt32(Console.ReadLine());
int []n2=new int [n1];
for (i = 0; i < n1; i++)
{
n2[i]=Convert.ToInt32(Console.ReadLine());
}
Console.WriteLine(xyz(n2,n1));
Console.ReadKey();
}
}
}

///////////////////////////////////////////////////////////////////////
74)nth decending

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
class Program
{
public static int xyz(int[] a,int n)
{
int []n1=(from s in a orderby s descending select s).ToArray();
int out1 = n1[n1.Length - n];
return out1;
}
static void Main(string[] args)
{
int n,i=0,b=0;
b=Convert.ToInt32(Console.ReadLine());
n = Convert.ToInt32(Console.ReadLine());
int[] ch = new int[n];
for (i = 0; i < n; i++)
{
ch[i] = Convert.ToInt32(Console.ReadLine());
}
Console.WriteLine(xyz(ch,b));
Console.ReadKey();
}
}

////////////////////////////////////////////////////////////////////////////
/////

75)maxspan

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace LagestPalindromeInaString
{
class Program
{
static void Main(string[] args)
{
int n = int.Parse(Console.ReadLine());
int[] nums = new int[n];
for (int i = 0; i < n; i++)
{
nums[i] = int.Parse(Console.ReadLine());
}
int output = maxSpan(nums);
Console.WriteLine(output);
}
public static int maxSpan(int[] nums)
{
int count = 1;
int maxspan = 0;
for (int i = 0; i < nums.Length; i++)
{
for (int j = i + 1; j < nums.Length; j++)
{
if (nums[i] == nums[j])
{
count++;
maxspan = count;
int number = nums[i];
}
}
}
return maxspan;
}
}
}
////////////////////////////////////////////////////////////////////////////////
////////////////////////////

76)
/*4.sandip-->taodjp
letter will be next of odd places*/

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication10
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Enter the string");
string name = Console.ReadLine();
string result= sourav(name);
Console.WriteLine(result);
Console.ReadLine();
}
public static string sourav(string name)
{
char[] ch = name.ToCharArray();
int s = 0;
string result = "";
List<char> li = new List<char>();
for (int i = 0; i < ch.Length; i++)
{
if (i % 2 == 0)
{
s = Convert.ToInt32(ch[i]) + 1;
li.Add(Convert.ToChar(s));
}
else
{
li.Add(ch[i]);
}
}
for (int i = 0; i < li.Count; i++)
{
result+=li[i];
}
return result;
}
}
}
////////////////////////////////////////////////////////////////////////////////
////////////////////
77)
//price = piepiepie
//
//
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
class a
{
public static string xy(string a)
{
StringBuilder sb = new StringBuilder();
StringBuilder sb1 = new StringBuilder();
int i;
int n1 = (from s in a select s).Count();
if (n1 % 2 == 0)
{
for (i = 1; i < a.Length; i += 2)
{
sb.Append(a[i]);
}
for (int j = 0; j < sb.ToString().Length; j++)
{
sb1.Append(sb);
}
}
else
{
for (i = 0; i < a.Length; i += 2)
{
sb.Append(a[i]);
}
for (int j = 0; j < sb.Length; j++)
{
sb1.Append(sb);
}
}
string k = sb1.ToString();
return k;
}
static void Main(string[] args)
{
string s1 = "price";
Console.WriteLine(xy(s1));
Console.ReadKey();
}
}

////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////
78)i/p-RAbbit
o/p-BBITar
//change the upper case to lower case and append the uppercase elements to end.
class Program
{
public static string xyz(string a)
{
StringBuilder sb = new StringBuilder();
StringBuilder sb1 = new StringBuilder();
int i=0;
char[] ch = a.ToCharArray();
for(i=0;i<ch.Length;i++)
{
if (char.IsUpper(ch[i]))
{
sb.Append(ch[i]);
}
else
sb1.Append(ch[i]);
}
sb1.Append(sb);
for (i = 0; i < sb1.Length; i++)
{
if(char.IsUpper(sb1[i]))
{
char.ToLower(sb1[i]);
}
else
{
char.ToUpper(sb1[i]);
}
}
string k = sb1.ToString();
return k;
}
static void Main(string[] args)
{
string s1 = "RaBit";
Console.WriteLine(xyz(s1));
Console.ReadKey();
}
}
////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////

79)
//Take an array , remove the duplicate elements keeping only the first occurance
. If no duplicate element is present print -1 only.
//Ex1:- {1,2,3,4,1,2,6,7,3}
//Output:- {1,2,3,4,6,7}
//Ex2:- {1,2,3,4,5}
//Output:- {-1

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
}
class Program
{
static void Main(string[] args)
{
int[] a = { 1, 2, 3, 4, 5,1 };
int[] out1 = RemoveEle(a);
foreach (var item in out1)
{
Console.WriteLine(item);
}

Console.ReadLine();
}
public static int[] RemoveEle(int[] i1)
{
int[] a = new int[1] { -1 };
List<int> li = new List<int>();
int flag = 0;
foreach (var item in i1)
{
if (Array.IndexOf(i1, item) != Array.LastIndexOf(i1, item))
{
flag = 1;
break;
}
}
if (flag == 0)
return a;
else
{
// i1 = i1.Distinct().ToArray();
foreach (var item in i1)
{
if (li.Contains(item) == false)
li.Add(item);
}

return li.ToArray();
}

}
}
////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////
80)
rabbit
t-i-b-b-a-r
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication2
{
class Program
{
public static string xy(string a)
{
int i;
char[] c={};
StringBuilder ab = new StringBuilder();

c = a.ToCharArray();
Array.Reverse(c);
for (i = 0; i < c.Length; i++)
{

ab.Append(c[i]);
if(i<c.Length-1)
ab.Append('-');
}
string s = ab.ToString();
return s;

}
static void Main(string[] args)
{
string s = "rabbit";
Console.WriteLine(xy(s));
Console.ReadKey();
}
}
}

////////////////////////////////////////////////////////////////////////////////
////////////////////

81)/*you have to take a string and one character .you have to find how many time
s the character is present in the string.
it will not have any special character/numbers.
the o/p will return the count and if no/characters are there then it will show i
nvalid i/p*/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication2
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Enter the string");
string s = Console.ReadLine();
Console.WriteLine("Enter the character");
char c = Convert.ToChar(Console.ReadLine());
int result = sourav(s,c);
Console.WriteLine(result);
Console.ReadLine();
}
public static int sourav(string s,char c)
{
int count=0;
char[] ch = s.ToCharArray();
for (int i = 0; i < ch.Length; i++)
{
if (ch[i] == c)
{
count++;
}
}
return count;
}
}
}
(need to add testcase)
////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////
82)/*
Take two strings from user which can be seperated by space.
* Find how many times the words of second string is present in the first string
.
If any two words in the first string are same then return -1.
* input1 :- "i am indian". input2 :- "i am bengali and also I am indian".
* output:- 3
*/
using System;
using System.Collections.Generic;
class UserProgramCode
{
public static int calcFrequency(string input1, string input2)
{
input1 = input1.ToLower();
input2 = input2.ToLower();
string[] s = input2.Split(' ');
string[] s1 = input1.Split(' ');
List<string> occurrence = new List<string>();
List<string> li = new List<string>();
int c = 0;
int flag = 0;
foreach (var item in s1)
{
if (!li.Contains(item))
{
li.Add(item);
}
else
{
flag++;
return -1;
}
}
foreach (var item in s1)
{
if (Array.IndexOf(s1, item) == Array.LastIndexOf(s1, item))
{
occurrence.Add(item);
}
}
foreach (var item in s)
{
if (occurrence.Contains(item))
{
c++;
}
}
return c;
}

}
class Program
{
public static void Main(string[] args)
{
string input1, input2;
int output = 0;
input1 = Console.ReadLine();
input2 = Console.ReadLine();
output = UserProgramCode.calcFrequency(input1, input2);
Console.WriteLine(output);
Console.ReadLine();
}
}
////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////
83)/*Find if a number is a power of 2. If it is find which power of 2 is it? If
the no. is ve return -1*/
pwer of two

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication8
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Enter the number");
int n = Convert.ToInt32(Console.ReadLine());
int result = sourav(n);
Console.WriteLine(result);
Console.ReadLine();
}
public static int sourav(int n)
{
int flag = 0;
int power = 0;
if (n < 0)
{
return -1;
}
for (int i = 0; i < n; i++)
{
flag = 0;
if (n == Math.Pow(2, i))
{
power = i;
flag++;
break;
}
}
if (flag > 0)
return power;
else
return -1;
}
}
}

////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////
84)/*Solve the quadratic equations x^2+y=40 and X^2-2y+z=0 to find the value of
y & z.
* values of x will be provided as an array of integers. Return the valu
es of y & z as a single array.
* The even indexes will contain the value of y and the odd the value of
z for each value of x.
* Return -1 if input array contains ve value. Return -2 if elements are
repeated in input array.*/

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication9
{
class Program
{
static void Main(string[] args)
{
int[] arr=new int[5];
Console.WriteLine("Enter the numbers of the array");
for (int i = 0; i < arr.Length; i++)
{
arr[i] = Convert.ToInt32(Console.ReadLine());
}
int[] result=sourav(arr);
for (int i = 0; i < result.Length; i++)
{
Console.WriteLine(result[i]+",");
}
Console.ReadLine();
}
public static int[] sourav(int[] arr)
{
List<int> li = new List<int>();
int[] arr1 = new int[]{-1};
int[] arr2 = new int[] { -2 };
List<int> li1 = new List<int>();
for (int i = 0; i < arr.Length; i++)
{
if (arr[i] < 0)
{
return arr1;
}
}
for (int i = 0; i < arr.Length; i++)
{
if (!li1.Contains(arr[i]))
{
li1.Add(arr[i]);
}
else
{
return arr2;
}
}

int y = 0,z=0;
for (int i = 0; i < arr.Length; i++)
{
y = (int)(40 - Math.Pow(arr[i], 2));
li.Add(y);
z = (int)((2 * y) - Math.Pow(arr[i], 2));
li.Add(z);
}
return li.ToArray();
}
}
}
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////
85)upper lower cases
//uuper to lower and lower to upper if all are in upper or in lower return -1

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace OrderByLengthThenAlpha
{
class a
{
public static string upperlower(string input)
{
int c1=0,c2=0;
string x = "-1";
char[] a = input.ToCharArray();
StringBuilder s = new StringBuilder();
foreach (var item1 in a)
{
if (char.IsUpper(item1))
{
c1++;
}
if (char.IsLower(item1))
{
c2++;
}
}
if (c1 == 0 || c2 == 0)
{
return x;
}
else
{
foreach (var item in a)
{
if (char.IsUpper(item))
{
s.Append(char.ToLower(item));
}
if (char.IsLower(item))
{
s.Append(char.ToUpper(item));
}
}
}

return s.ToString();
}
static void Main(string[] args)
{
string i = "abcdef";
string res = upperlower(i);
Console.WriteLine(res);
Console.ReadKey();
}
}
}
////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////
86)
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
//3.take an integer array an find the highest difference.(the difference will on
ly be valid when the left element is smaller than the right if you proceed from
left to right)
//business rule-
//1.if there is any negetive number print -2
//2.if there is is only one element or more than 10 element print -3.
//sample i/p
//7-------------------------------size of the array
//2
//3
//10
//4
//6
//8
//1
//o/p
//8
namespace ConsoleApplication28
{
class Program
{
static void Main(string[] args)
{
int size = Convert.ToInt32(Console.ReadLine());
int[] a = new int[size];
for (int i = 0; i < a.Length; i++)
{
a[i] = Convert.ToInt32(Console.ReadLine());
}
int result = highestdiff(a);
Console.WriteLine(result);
Console.ReadLine();
}
public static int highestdiff(int[] input)
{
List<int> res = new List<int>();
int p = 0;
if (input.Length == 1 || input.Length > 9)
{
return -3;
}
else
{
for (int i = 0; i < input.Length; i++)
{
for (int j = i + 1; j < input.Length; j++)
{

if (input[i] < input[j])


{
res.Add(input[j] - input[i]);
res.Sort();
res.Reverse();
int[] a = res.ToArray();
p = a[0];
}
}
//else
//{
// return -2;
//}
}
}
for (int i = 0; i < input.Length; i++)
{
if (input[i] < 0)
{
return -2;
}
}
return p;
}
}
}
////////////////////////////////////////////////////////////////////////////////
/////////////////////////

87)//INPUT AN INTEGER ARRAY.ADD A NUMBER TO A PARTICULAR POSITION AND SORT THAT


IN DESCENDING ORDER.(audit 7)

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
class a
{
static void Main(string[] args)
{
int size = Convert.ToInt32(Console.ReadLine());
int[] a = new int[size];
for (int i = 0; i < a.Length; i++)
{
a[i] = Convert.ToInt32(Console.ReadLine());
}
int x=Convert.ToInt32(Console.ReadLine());
int y = Convert.ToInt32(Console.ReadLine());
int[] res = addnumbertoarray(a,x,y);
for (int j = 0; j < res.Length; j++)
{
Console.WriteLine(res[j]);
}
Console.ReadLine();

}
public static int[] addnumbertoarray(int[] a, int b, int c)
{
List<int> li = a.ToList();
li.Insert(b - 1, c);
li.Sort();
li.Reverse();
return li.ToArray();
}
}

////////////////////////////////////////////////////////////////////////////////
///////////////////////
88)//1. Take a string from user and calculate the sum of digits and move to end.
(apple1234)
//Business Rules:-
//a. If the string does not have any digits then print -1.
//b. If the string does not have any characters then print -2.
//c. If the string has any special character then print -3.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

class a
{
public static string appendsum(string input)
{
int sum = 0;
int counter = 0;
int counter1 = 0;
string x = "-1";
string y = "-2";
string z = "-3";
StringBuilder s = new StringBuilder();
StringBuilder s1 = new StringBuilder();
char[] a = input.ToCharArray();
if (a.Length == 0)
{
return y;
}
else
{
foreach (var item in a)
{
if (char.IsDigit(item))
{
s.Append(item);
counter++;
}
//else
// return x;
}
if (counter == 0)
{
return x;
}
foreach (var item1 in a)
{
if (char.IsLetter(item1))
{
s1.Append(item1);
}
}
foreach (var item3 in a)
{
if (char.IsSymbol(item3))
{
counter1++;
}
}
if (counter1 > 0)
{
return z;
}
string k = s1.ToString();
string j = s.ToString();
int n = Convert.ToInt32(j);
while (n > 0)
{
int rem = n % 10;
sum = sum + rem;
n = n / 10;
}
string join = Convert.ToString(sum);
string result = k + join;
return result;
}
}
static void Main(string[] args)
{
string i = Console.ReadLine();
string result = appendsum(i);
Console.WriteLine(result);
Console.ReadLine();
}
}

////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////
89)//5. write number of count of char in a string .
//string should be letter type only .
//eg. helLo London london
//should return count for both l and L
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
class UserProgramCode
{
static void Main(string[] args)
{
string i = "helLo London london";
char j = 'l';
int res = findOccurence(i, j);
Console.WriteLine(res);
Console.ReadLine();
}
public static int findOccurence(string input1, char input2)
{
input1= input1.ToLower();
input2 = char.ToLower(input2);
int c = 0;
char[] ch = input1.ToCharArray();
for (int i = 0; i < ch.Length; i++)
{
if (char.IsLetter(ch[i]))
{
if (ch[i] == input2)
{
c++;
}
}
}
return c;
}
}
////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////
//90. ENTER A STRING ARRAY ,SIZE OF DAT ARRAY AND A CHARACTER,
//AND FIND THE COUNT OF THE STRINGS STARTS WITH THE GIVEN CHARACTER.
//EG1-
//SIZE=3,
//{APPLE,ANT,MANGO},
//CH=A,
//OUTPUT=2
//EG2-
//SIZE =2,
//{@ABC,KLMN},
//CH=B,
//OUTPUT=INVALID INPUT

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
class Program
{
static void Main(string[] args)
{
int size = Convert.ToInt32(Console.ReadLine());
string[] a = new string[size];
for (int i = 0; i < a.Length; i++)
{
a[i] = Console.ReadLine();
}
char c = Convert.ToChar(Console.ReadLine());
int res = countstring(a, c);
if (res == 0)
{
Console.WriteLine("INVALID INPUT");
}
else
{
Console.WriteLine(res);
}
Console.ReadLine();
}

public static int countstring(string[] input, char a)


{
int count = 0;
//int count1 = 0;
//if (char.IsSymbol(a) || char.IsPunctuation(a))
//{
// return -1;
//}
//else
//{
string k = a.ToString();
for (int i = 0; i < input.Length; i++)
{
if (input[i].StartsWith(k))
{
count++;
}
}

return count;
}
}

////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////
91)//Count vowels in a given string and test cases
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
class a
{
static void Main(string[] args)
{
string a = Console.ReadLine();
int res = countvowel(a);
Console.WriteLine(res);
Console.ReadLine();

}
public static int countvowel(string a)
{
a.ToLower();
int count =0;
foreach (var item in a)
{
if (char.IsLetter(item))
{
if (item == 'a' || item == 'e' || item == 'i' || item == 'o' ||
item == 'u')
{
count++;
}
}
}
foreach (var item1 in a)
{
if (char.IsDigit(item1) || char.IsSymbol(item1) || char.IsPunctuatio
n(item1))
{
return -2;
}
}
if (count == 0)
{
return -1;
}
return count;
}
}
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////
92)//22)Program to count the number of vowels in the given string.
//If the string contains any special character the return -1.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication93
{
class Program
{
static void Main(string[] args)
{
string i = Console.ReadLine();
int res = countvowel(i);
Console.WriteLine(res);
Console.ReadLine();
}
public static int countvowel(string input)
{
input.ToLower();
char[] ch = input.ToCharArray();
int count =0;
int c = 0;
for (int i = 0; i < ch.Length; i++)
{
if (ch[i] == 'a' || ch[i] == 'e' || ch[i] == 'i' ||ch[i] == 'o'
|| ch[i] == 'u')
{
count++;
}
}
foreach (var item in ch)
{
if (char.IsSymbol(item) || char.IsPunctuation(item))
{
c++;
break;
}
}
if (c == 1)
{
return -1;
}
return count;
}
}
}
////////////////////////////////////////////////////////////////////////////////
/////////////
//93) Write a method that receives a list of Strings and finds the index of that
string containg the maximum
number of vowls. In case their is a tie find the last position of such string. I
f no such string is
found return -1.
Input: {"Hi","Piano","Guitar","Violin"} Output : 3

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication80
{
class Program
{
public static int maxVowel(List<string> li)
{
//int c=-1;
List<string> li2 = new List<string>();
List<int> li3 = new List<int>();
foreach (var item in li)
{ int count=0;
foreach (var item1 in item)
{
if (item1 == 'a' || item1 == 'e' || item1 == 'i' || item1 ==
'o' || item1 == 'u' ||
item1 == 'A' || item1 == 'E' || item1 == 'I' || item1 ==
'O' || item1 == 'U')
count++;
}
li3.Add(count);
}
li3.Sort();
int c = 0;
foreach (var item in li3)
{
if (item == 0)
c++;
}
if (c == li3.Count)
return -1;

int n = li3[li3.Count-1];
return li3.LastIndexOf(n);
}
static void Main(string[] args)
{
List<string> li1 = new List<string>();
for (int i = 0; i < 4; i++)
{
li1.Add(Console.ReadLine());
}
int result = maxVowel(li1);
Console.WriteLine(result);
Console.ReadLine();
}
}
}
--------------------------------------------------------------------------------
--------------
--------------------------------------------------------------------------------
--------------

namespace ConsoleApplication50
namespace ConsoleApplication50
{
class Program
{
static void Main(string[] args)
{
int a = Convert.ToInt32(Console.ReadLine());
string[] str = new string[a];
for (int i = 0; i <a; i++)
{
str[i] = Console.ReadLine();
}
int result = MaxIndex(str);
Console.WriteLine(result);
Console.ReadLine();
}
public static int MaxIndex(string[] input)
{
int c = 0;
List<int> li = new List<int>();
foreach (var item in input)
{
c = 0;
foreach (var item1 in item)
{
if (item1 == 'a' | item1 == 'e' | item1 == 'i' | item1 == 'o
' | item1 == 'u' | item1 == 'A' |
item1 == 'E' | item1 == 'I' | item1 == 'O' | item1 == 'U
')
c++;
}
li.Add(c);
}
if (c == 0)
return -1;
else
{
int a = li.Max();
int final = li.LastIndexOf(a);
return final;
}
}
}
}

////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////
94)// 15) Display 1 if there are all 5 vowels in alphabetical order
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
class a
{
static void Main(string[] args)
{
string a = Console.ReadLine();
int result = vowelorder(a);
Console.WriteLine(result);
Console.ReadLine();
}
public static int vowelorder(string input)
{
input.ToLower();
int output = 0;
StringBuilder sb = new StringBuilder();
char[] a = input.ToCharArray();
for (int i = 0; i < a.Length; i++)
{
if (a[i] == 'a' || a[i] == 'e' || a[i] == 'i' || a[i] == 'o' || a[i]
== 'u')
{
sb.Append(a[i]);
}
if (sb.ToString() == "aeiou")
{
output = 1;
}
else
output = -1;
}
return output;
}
}
.........................or,........................

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace vowelcheck
{
class Program
{
static void Main(string[] args)
{
string s = Console.ReadLine();
char[] ch = s.ToCharArray();
StringBuilder sb = new StringBuilder();
for (int i = 0; i < ch.Length; i++)
{
if (ch[i] == 'a' || ch[i] == 'e' || ch[i] == 'i' || ch[i] == 'o'
|| ch[i] == 'u')
{
sb.Append(ch[i]);
}
}
int flag = 0;
string str = sb.ToString();
char[] c = str.ToCharArray();
for (int i = 0; i < c.Length-1; i++)
{
if (c[i] <= c[i + 1])
{
flag = 0;
}
else
{
flag = 1;
break;
}
}
Console.WriteLine(flag);
}
}
}
////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////
95) remove the vowels in even postion
eg:commitment
ans:cmmitmnt
string x = Console.ReadLine();
string y = " ";
char[] ch = x.ToCharArray();
StringBuilder sb=new StringBuilder();
for (int i = 0; i < x.Length;i++)
{
if (i % 2 != 0)
{
if (ch[i] == 'a' || ch[i] == 'e' || ch[i] == 'i' || ch[i] ==
'o' || ch[i] == 'u')
{
}
else
{
sb.Append(ch[i]);
}
}
else
{
sb.Append(ch[i]);
}
}
y = sb.ToString();
Console.WriteLine(y);
Console.ReadKey();
////////////////////////////////////////////////////////////////////////////////
///////////////
96) next-vowels
StringBuilder b = new StringBuilder();
foreach (char ch in a)
{
if (ch >= 'a' && ch <= 'd')
b.Append('e');
else if (ch >= 'e' && ch <= 'h')
b.Append('i');
else if (ch >= 'g' && ch <= 'n')
b.Append('o');
else if (ch >= 'p' && ch <= 't')
b.Append('u');
else if (ch >= 'v' && ch <= 'z')
b.Append('a');
}
string c = b.ToString();
return c;
}
////////////////////////////////////////////////////////////////////////////////
////////////////////////////
97)count the vowels in the string array in case there is a tie display the first
occurance of the given string
eg: "sun rises in the east" => o/p: rises
static void Main(string[] args)
{
string input1 = "sun rises in the east";
int count = 0, temp = 0;
string s1 = "aeiouAEIOU";
string output1 = " ";
char[] ch = s1.ToCharArray();
StringBuilder sb = new StringBuilder();
string[] str = input1.Split(' ');
foreach (var i in str)
{
count = 0;
foreach (var j in i)
{
if (s1.Contains(j))
{
count++;
}
}
if (count > temp)
{
temp = count;
output1 = i;
}
}
Console.WriteLine(output1);
Console.Read();
}
}
}
////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////
98)palidrome with count 2 vowel
int y=0;
var z = 0;
int op = 0;
char[] ch = a.ToCharArray();
Array.Reverse(ch);
string f = new string(ch);
if (f==a)
{
y = 1;
}
if (y == 1)
{
z = ((from pr in ch where (pr == 'a' || pr == 'e' || pr == 'i' |
| pr == 'o' || pr == 'u') select pr).Distinct()).Count();
if (z > 1)
{
op = 1;
}
else
{
op = -1;
}
}
else
{
op = -3;
}
return op;

////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////
99)Next vowel and next consonant
to find the next vowel and next consonant
public static string xy(string a)
{
StringBuilder sb=new StringBuilder();
foreach (var v in a)
{
char vy=(v=='a'?'e':v=='e'?'i':v=='i'?'o':v=='o'?'u':v=='u'?'a':
v=='Z'?'A':v=='z'?'a':v==' '?' ':(char)(v+1));
sb.Append(vy);
}
string k=sb.ToString();
return k;
}
static void Main(string[] args)
{
string a = "the sun rises in the east";
Console.WriteLine(xy(a));
Console.ReadKey();
}
}

.............................ort................................................
.......
Next Vowel and Next Consonant
eg..
using System;
using System.Collections.Generic;
using System.Text;
namespace NumWords
{
class Program
{
static void Main(string[] args)
{
Console.Write("Enter words: ");
string n = Console.ReadLine();
int flag=0;
StringBuilder sb= new StringBuilder();
n = n.ToLower();
foreach (char c in n)
{
if (!(c >= 'a' && c <= 'z'))
{
flag = 1;
break;
}
}
if (flag == 0)
{
foreach (char c in n)
{
if (c == 'a' || c=='e' || c=='i' || c=='o' || c=='u')
sb.Append(Convert.ToChar(c+1));
if (c >= 'b' && c <= 'd')
sb.Append('e');
if (c >= 'f' && c <= 'h')
sb.Append('i');
if (c >= 'j' && c <= 'n')
sb.Append('o');
if (c >= 'p' && c <= 't')
sb.Append('u');
if (c >= 'v' && c <= 'z')
sb.Append('a');
}
}
string s1 = sb.ToString();
s1 = s1.ToUpper();
Console.WriteLine(s1);
}
}
}
////////////////////////////////////////////////////////////////////////////////
/////////////
100)In a string odd position alphabets into the next alphabet in order
using System;
using System.Collections.Generic;
using System.Text;
using System.Linq;
namespace NumWords
{
class Program
{
static void Main(string[] args)
{
string s = Console.ReadLine();
char[] ch = s.ToCharArray();
StringBuilder sb = new StringBuilder();
string output = "";
int flag = 0;
foreach (char c in ch)
{
if (!(c >= 'a' && c <= 'z'))
{
output += -1;
flag = 1;
break;
}
}
if (flag == 0)
{
foreach (char c in s)
{
int i = Convert.ToInt32(s.IndexOf(c));
if (i % 2 == 0)
{
sb.Append(c);
}
else
sb.Append(Convert.ToChar(c+1));
}
}
Console.WriteLine(sb.ToString());
}
}
}

////////////////////////////////////////////////////////////////////////////////
//////////////////////////////
101)word containing max vowel
public static string xy(string a)
{
string s5 = "";
StringBuilder sb=new StringBuilder();
int j=0,temp=0;
char []ch={' '};
string []s1=a.Split(ch,StringSplitOptions.RemoveEmptyEntries);
for (int i = 0; i < s1.Length; i++)
{
int c = 0;
char[] ch1 = s1[i].ToCharArray();
for (j = 0; j < ch1.Length; j++)
{
if (ch1[j] == 'a' || ch1[j] == 'e' || ch1[j] == 'i' || ch1[j
] == 'o' || ch1[j] == 'u')
{
c++;
}
}
if (c > temp)
{
temp = c;
s5 = new string(ch1);
}
else
{
}
}
return s5;

}
////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////
102)
//Write a method that takes a string array and returns another array after keepi
ng only integers in descending order.
//Eg:- Input :- {"cts1","tcs","123","q1","5"}
//Output :- {123,5}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication92
{
class Program
{
static void Main(string[] args)
{
string[] str = { "cts1", "tcs", "123", "q1", "5" };
string[] res = onlydigit(str);
for (int i = 0; i < res.Length; i++)
{
Console.WriteLine(res[i]);
}
Console.ReadLine();
}
public static string[] onlydigit(string[] input)
{
string result = "";
List<string> li = new List<string>();
for (int i = 0; i < input.Length; i++)
{
result = "";
int flag = 0;
char[] ch=input[i].ToCharArray();
for (int j = 0; j < ch.Length; j++)
{
if (!char.IsDigit(ch[j]))
{
flag++;
break;
}
else
{ flag=0;
result += ch[j];
}
}
if(flag==0)
li.Add(result);
}
li.Sort();
li.ToArray();
string[] arr=new string[li.Count];
for (int i = 0; i < li.Count; i++)
{
arr[i] = li[i].ToString();
}
return arr;
}
}
}

////////////////////////////////////////////////////////////////////////////////
//////////////////
103)kolkata to kolat
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication120
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("enter the string");
string s = Console.ReadLine();
string pp = Duplicatee(s);
Console.WriteLine(pp);
Console.ReadLine();

}
static string Duplicatee(string ss)
{
List<char> li = new List<char>();
char[] a = ss.ToCharArray();
foreach (var item in a)
{
if (li.Contains(item)==false)
{
li.Add(item);
}
}
char[] pp = li.ToArray();
string sss = new string(pp);
return sss;

}
}
}

////////////////////////////////////////////////////////////////////////////////
//////
104)kolkata to olt
print only unique elements
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication121
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("enter the string");
string s = Console.ReadLine();
string pp = Duplicatee(s);
Console.WriteLine(pp);
Console.ReadLine();
}
static string Duplicatee(string ss)
{
List<char> ch = new List<char>();
char[] chw = ss.ToCharArray();
foreach (var item in chw)
{
if (Array.IndexOf(chw, item) == Array.LastIndexOf(chw, item))
{
ch.Add(item);
}
}
char[] p = ch.ToArray();
string d = new String(p);
return (d);
}
}
}

////////////////////////////////////////////////////////////////////////////////
////////////////////////

105)fetch only digits from a string array and return it sorted in descending ord
er
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
//Write a method that takes a string array and returns another array after keepi
ng only integers in descending order.
//Eg:- Input :- {"cts1","tcs","123","q1","5"}
//Output :- {123,5}
namespace ConsoleApplication92
{
class Program
{
static void Main(string[] args)
{
string[] str = { "cts1", "tcs", "123", "q1", "5" };
string[] res = onlydigit(str);
for (int i = 0; i < res.Length; i++)
{
Console.WriteLine(res[i]);
}
Console.ReadLine();
}
public static string[] onlydigit(string[] input)
{
string result = "";
List<string> li = new List<string>();
for (int i = 0; i < input.Length; i++)
{
result = "";
int flag = 0;
char[] ch=input[i].ToCharArray();
for (int j = 0; j < ch.Length; j++)
{
if (!char.IsDigit(ch[j]))
{
flag++;
break;
}
else
{ flag=0;
result += ch[j];
}
}
if(flag==0)
li.Add(result);
}
li.Sort();
li.ToArray();
string[] arr=new string[li.Count];
for (int i = 0; i < li.Count; i++)
{
arr[i] = li[i].ToString();
}
return arr;
}
}
}
////////////////////////////////////////////////////////////////////////////////
////////////////////////
106)//Create a method and return the largest Armstrong number between input1 an
d input2.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication83
{
class Program
{
public static int FindMaxArmstrong(int input1, int input2)
{
int sum=0;
for (int i = input2; i >= input1; i--)
{
sum = 0;
int j = i;
while (j != 0)
{
int rem = j % 10;
sum = sum + rem * rem * rem;
j = j / 10;
}
if (sum == i)
break;
}
return sum;
}
static void Main(string[] args)
{
Console.WriteLine("enter 1st no");
int n1 = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("enter 2nd no");
int n2 = Convert.ToInt32(Console.ReadLine());
int result = FindMaxArmstrong(n1, n2);
Console.WriteLine(result);
Console.ReadLine();
}
}
}
////////////////////////////////////////////////////////////////////////////////
//////////////////////////////

107)
//3. Write a method that takes a string array and returns the count of palindrom
es in the string array.
//If no palindrome is present the return -1.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
class program
{
public static int countpalindrome(string[] input)
{
int count = 0;
for (int i = 0; i < input.Length; i++)
{string s="";
char[] ch = input[i].ToCharArray();
for (int j = ch.Length-1; j >=0 ; j--)
{
s+=ch[j];
}
if(s==input[i])
{
count++;
}
}
if (count > 0)
return count;
else
return -1;

}
static void Main(string[] args)
{
string[] arr=new string[3];
Console.WriteLine("Enter the names");
for (int i = 0; i < arr.Length; i++)
{
arr[i]=Console.ReadLine();
}
int result=countpalindrome(arr);
Console.WriteLine(result);
Console.ReadLine();
}

////////////////////////////////////////////////////////////////////////////////
////////////////////
108)Calculate sum of Fibonacci series elements
Input1=4
Output = 4
Input2= 15
Output=986

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
class Program
{
public static void Main(string[] args)
{
int n = Convert.ToInt32(Console.ReadLine());
Console.WriteLine(UserMainCode.getSumOfNfibos(n));
Console.ReadLine();
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

class UserMainCode
{
public static int getSumOfNfibos(int n)
{
// fill your code here
List<int> li = new List<int>();
int a = 0, b = 1;
int c = 0;
li.Add(a);
li.Add(b);
for (int i=2; i<n; i++)
{
c = a + b;
a = b;
b = c;
li.Add(c);
}
int sum = 0;
for (int j = 0; j< li.Count; j++)
{
sum = sum + li[j];
}
return sum;
}
}

////////////////////////////////////////////////////////////////////////////////
//////////////
109)The Next Palindrome

using System;
public class UserMainCode
{
public static int FindNextPalindrome(int n)
{
int res;
for (int i = n+1; ; i++)
{
string s=i.ToString();
char[] a = s.ToCharArray();
Array.Reverse(a);
string s1 = new string(a);
if(s==s1)
{
res = Convert.ToInt32(s);
break;
}
}
return res;
}
}
////////////////////////////////////////////////////////////////////////////////
//////////////////////
110)using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

//3. Take an array as input and return an array after replcaing the elements wit
h the next prime number.

class Program
{
static void Main(string[] args)
{
int[] a = { 3, 4, 5, 67, 88 };
int [] o=UserProgramCode.NextPrime(a);
foreach (var item in o)
{
Console.Write("{0} ",item);
}
Console.ReadKey();
}
}
class UserProgramCode
{
//
//3. Take an array as input and return an array after replcaing the elem
ents with the next prime number.
public static int[] NextPrime(int [] input1)
{
List<int> li=new List<int>();
foreach (var item in input1)
{
li.Add(prime(item+1));
}
int[] b = li.ToArray();
return b;
}
public static int prime(int a)
{
int c=0,i=0;
for ( i = 2; i < a; i++)
{
if(a%i==0)
{
c++;
break;
}
}
if(c>0)
{
return prime(a + 1);
}
else
return a;

}
}
////////////////////////////////////////////////////////////////////////////////
///

111)using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Sir
{
class Class1
{
public static List<int> fun(int[] a)
{
List<int> res = new List<int>();
for (int j = 0; j < a.Length; j++)
{
int count = 0;
for (int k = 1; k <= a[j]; k++)
{
if (a[j] % k == 0)
{
count++;
}
}
if (count == 2)
{
res.Add(a[j]);
}
}
return res;
}
}
}

////////////////////////////////////////////////////////////////////////////////
/////////////////////////////
112)//12)Remove duplicates elements from integer array and sum all even numbers
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
class a
{
static void Main(string[] args)
{
int[] a = { 1, 2, 3, 4, 4, 6, 5, 8, 4, 3, 2 };
int res = sumofnonduplicate(a);
//for (int i = 0; i < res.Length; i++)
//{

Console.WriteLine(res);
//}
Console.ReadLine();
}
public static int sumofnonduplicate(int[] input)
{
List<int> li = new List<int>();
foreach (var item in input)
{
if (!li.Contains(item))
{
li.Add(item);
}
}
int sum = 0;
//int rem = 0;
//int count = 0;
int[] a = li.ToArray();
for (int i = 0; i < a.Length; i++)
{
if (a[i] % 2 == 0)
{
sum = sum + a[i];

}
}
return sum;
}
}
////////////////////////////////////////////////////////////////////////////////
//////////////////////
113)//String Input1= AAAAA12345 ;
//String Input2= AAAAA23456 ;
//int Input3=4;
//UserMainCode(Input1,Input2,Input3)
//Logic : Output1=(Input1-Input2)*Input3

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
class a
{
static void Main(string[] args)
{
string a = Console.ReadLine();
string b = Console.ReadLine();
int i = Convert.ToInt32(Console.ReadLine());
int res = cal(a, b, i);
Console.WriteLine(res);
Console.ReadLine();
}
public static int cal(string input1, string input2, int input3)
{
int b =0;
int a=0;
int result = 0;
StringBuilder sb = new StringBuilder();
StringBuilder sb1 = new StringBuilder();
for (int i = 0; i < input1.Length; i++)
{
if (char.IsDigit(input1[i]))
{
sb.Append(input1[i]);
}
}
for (int j = 0; j < input2.Length; j++)
{
if (char.IsDigit(input2[j]))
{
sb1.Append(input2[j]);
}
}
string e= sb.ToString();
string f = sb1.ToString();
a = Convert.ToInt32(e);
b = Convert.ToInt32(f);
if (a > b)
{
result = (a - b) * input3;
}
else
{
result = (b - a) * input3;
}
return result;
}
}
////////////////////////////////////////////////////////////////////////////////
/////

114)//6)Display the length of the smallest string in given string array


o/p:sq-antu,in-dia,abc,- y x
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
class a
{
static void Main(string[] args)
{
string[] str = { "sq antu", "In dia", "abc"," y x"};
string[] res = countstring(str);
for (int i = 0; i < res.Length; i++)
{
Console.WriteLine(res[i]);
}
Console.ReadLine();
}
public static string[] countstring(string[] input)
{
string[] res = new string[input.Length] ;
//StringBuilder s = new StringBuilder();
//List<string> li = new List<string>();
for (int i = 0; i < input.Length; i ++)
{
char[] ch = input[i].ToCharArray();
for (int j = 0; j < ch.Length; j=j+2)
{

if (char.IsWhiteSpace(ch[j]))
{
ch[j] = '-';
}
res[i] = new string(ch);
}

}
return res;
}
}
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////
115)subset...

using System;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
Subset of addition
namespace ConsoleApplication115
{
class Program
{
static void Main(string[] args)
{
int[] a = { 1, 2, 3, 4, 5,6 };
Liststringli=new Liststring();
for (int i = 0; i a.Length; i++)
{
for (int j = 0; j a.Length; j++)
{
for (int k = j+1; k a.Length; k++)
{
if ((a[k]+a[j]) == a[i])
li.Add(a[j] + , + a[k] + , + a[i]);
}
}
}
foreach (var item in li)
{
Console.WriteLine(item);
}
Console.ReadLine();
}
}
}

////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////
116)swap
//4. Swap consecutive two elements of a string. If the string is of odd length t
hen keep the last character same.
//Eg:- IP:- "india" OP:-"niida".
//IP:- "indi" OP:-"niid".

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
class a
{
static void Main(string[] args)
{
string i = Console.ReadLine();
string res = swapadjacent(i);
Console.WriteLine(res);
Console.ReadLine();
}
public static string swapadjacent(string input1)
{

char[] s = input1.ToCharArray();
char temp;
string result = "";
for (int i = 0; i < s.Length - 1; i = i+2)
{
temp = ' ';
temp = s[i];
s[i] = s[i + 1];
s[i + 1] = temp;
}
result = new string(s);
return result;
}
}

////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////
117)
//10.Take an input string and keep only first occurance of all characters except
for whitespaces.
//Eg:- IP- "hi this is a test".
// OP- "hi ts a e".
//If no duplicate element is found then print "No duplicates".
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
class a
{
static void Main(string[] args)
{
string i = "hi this is a test";
string res = repeatation(i);
Console.WriteLine(res);
Console.ReadLine();
}
public static string repeatation(string str)
{
//int c = 0;
StringBuilder sb = new StringBuilder();
foreach (char s in str)
{
if (char.IsLetter(s))
{
if (!sb.ToString().Contains(s))
{
sb.Append(s);
}

}
else if (char.IsWhiteSpace(s))
{
sb.Append(s);
}
}
//foreach (char s1 in str)
//{
// if (char.IsLetter(s1))
// {
// if (sb.ToString().Contains(s1))
// {
// return "No duplicates";
// }
// }
//}
//char[] ch = str.ToCharArray();
//for (int i = 0; i < ch.Length; i++)
//{
// if(ch[i] != ' ')
// {
// if(Array.IndexOf(ch,ch[i])!=Array.LastIndexOf(ch,ch[i]))
// {
// c++;
// break;
// }
// }
//}
//if (c==1)
//{
// return "No duplicates";
//}
string res = sb.ToString();
char[] ch1 = { ' ' };
string[] res1 = res.Split(ch1, StringSplitOptions.RemoveEmptyEntries);
string res2 = string.Join(" ", res1);
return res2;
}
}

////////////////////////////////////////////////////////////////////////////////
/////////////////
118)101. replace the "is" word with "is not" not the letter "i s"
ip=hi this
op=hi this
ip=hi this is
op=hi this is not
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace StringReplace
{
class Program
{
public static string ReplaceValue(string input)
{
string output = string.Empty;
StringBuilder sb = new StringBuilder();
string[] s = input.Split(' ');
foreach (string s1 in s)
{
if (s1 == "is")
{
sb.Append("is not");
sb.Append(' ');
}
else
{
sb.Append(s1);
sb.Append(' ');
}
}
return sb.ToString().Trim();
}
static void Main(string[] args)
{
string input = Console.ReadLine();
string output = ReplaceValue(input);
Console.WriteLine(output);
}
}
}

////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////
119) Adding years to date. If date format is wrong return -1. If years given is
negative return -2
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication5
{
class Program
{
public static void Main(string[] args)
{
string input1 = "27/09/1992";
int input2=2;
int output1 = 0;
string output=" ";
DateTime dt;
bool res = DateTime.TryParseExact(input1, "dd/MM/yyyy", null, System
.Globalization.DateTimeStyles.None, out dt);
if (res == true)
{
dt = dt.AddYears(input2);
output = dt.ToString("dd/MM/yyyy");
// Console.WriteLine(output);
output1 = 1;
}
if (res == false)
{
output1 = -1;
}
if (input2 < 0)
{
output1 = -2;
}
Console.WriteLine(output1);
Console.Read();
}
}
}

////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////

120)datetime format - dd/MM/yyyy


eg: add 1 year to the given date and find the DAY of that date
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
namespace ConsoleApplication5
{
class Program
{
public static void Main(string[] args)
{
string input1 = "27/19/1991";
string output1 = " ";
DateTime dt;
bool res = DateTime.TryParseExact(input1, "dd/MM/yyyy", null, System
.Globalization.DateTimeStyles.None, out dt);
if (res == true)
{
dt = dt.AddYears(1);
output1 = dt.DayOfWeek.ToString();
}
else
{
output1 = "-1";
}
Console.WriteLine(output1);
Console.Read();
}
}
}
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////
121) vote scenario
check whether the person is eligible to vote
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
namespace ConsoleApplication5
{
class Program
{
public static void Main(string[] args)
{
string input1 = "27/09/1999";
string output1 = " ";
DateTime dt;
bool res = DateTime.TryParseExact(input1, "dd/MM/yyyy", null, Syste
m.Globalization.DateTimeStyles.None, out dt);
if (res == true)
{
int month = DateTime.Now.Month - dt.Month;
int year = DateTime.Now.Year - dt.Year;
if (month < 0)
{
year = year - 1;
month = month + 12;
}
if (year > 18)
{
output1 = "eligible to vote";
}
else
{
output1 = "not eligible";
}
}
Console.WriteLine(output1);
Console.Read();
}
}
}
////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////
123)Add days to date
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
namespace ConsoleApplication5
{
class Program
{
public static void Main(string[] args)
{
string input1 = "27/09/1999";
string output1 = " ";
DateTime dt;
bool res = DateTime.TryParseExact(input1, "dd/MM/yyyy", null, System
.Globalization.DateTimeStyles.None, out dt);
if (res == true)
{
dt=dt.AddDays(16);
output1=dt.ToString("dd/MM/yyyy");
}
else
{
output1="-1";
}
Console.WriteLine(output1);
Console.Read();
}
}
}
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////

124)checking time format ('hh:mm am' or 'hh:mm pm')


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
namespace ConsoleApplication5
{
class Program
{
public static void Main(string[] args)
{
string input1 = "27/09/1999 01:25 AM";
int output1 = 0;
DateTime dt;
char[] ch = input1.ToCharArray();
bool res = DateTime.TryParseExact(input1, "dd/MM/yyyy h:mm tt", null
, System.Globalization.DateTimeStyles.None, out dt);
if (res == true)
{
if ((ch[ch.Length - 2] == 'A' || ch[ch.Length - 2] == 'P') && ch
[ch.Length - 1] == 'M')
{
output1 = 1;
}
/*if ((input1.Substring(input1.Length - 2, 1) ==
&quot;A&quot; || input1.Substring(input1.Length - 2, 1) == &quot;P&quot;)
&amp;&amp; input1.Substring(input1.Length - 1) == &quot;M&qu
ot;)
{
output1 = 1;
}*/
}
else
{
output1 = -1;
}
Console.WriteLine(output1);
Console.Read();
}
}
}
////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////
125)car parking...
car parking scenario:2 inputs are given as string that should be converted to da
tetime format and calculate the hours
and calculate the charges for car parking.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication5
{
class Program
{
static void Main(string[] args)
{
string input1 = "1991/09/12 09:45:56";
string input2 = "1991/09/12 10:45:57";
double output1 = 0;
DateTime dt;
DateTime dt1;
double duration = 0;
bool res = DateTime.TryParseExact(input1, "yyyy/MM/dd hh:mm:ss", nul
l, System.Globalization.DateTimeStyles.None, out dt);
bool res1 = DateTime.TryParseExact(input2, "yyyy/MM/dd hh:mm:ss", nu
ll, System.Globalization.DateTimeStyles.None, out dt1);
if (res == false || res1 == false)
{
output1 = -1;
}
else
{
if (dt > dt1)
{
output1 = -2;
}
else
{
duration = Math.Ceiling(dt1.Subtract(dt).TotalHours);
if (duration > 24)
{
output1 = -3;
}
else if (duration <= 3)
{
output1 = 2;
}
else if (duration > 3 && duration <= 24)
{
output1 = 2 + (0.50 * (duration - 3));
}
}
}
Console.WriteLine(output1);
Console.Read();
}
}
}

////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////
126)EX::: DATETIME---TIMESPAN
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
namespace ConsoleApplication5
{
class Program
{
public static void Main(string[] args)
{
DateTime dt;
DateTime dt2;
TimeSpan ts;
int s = 0;
string s3 = "";
string s1 = "20-12-1991 04:20:22";
string s2 = "21-12-1991 05:20:22";
bool res = DateTime.TryParseExact(s1, "dd-MM-yyyy hh:mm:ss", null, S
ystem.Globalization.DateTimeStyles.None, out dt);
bool res1 = DateTime.TryParseExact(s2, "dd-MM-yyyy hh:mm:ss", null,
System.Globalization.DateTimeStyles.None, out dt2);
if (res == true && res1 == true)
{
if (dt2 > dt)
{
s = (int)dt2.Subtract(dt).TotalHours;
ts = dt2.Subtract(dt);
s3 = ts.ToString();
}
else
{
s = (int)dt.Subtract(dt2).TotalHours;
ts = dt.Subtract(dt2);
s3 = ts.ToString();
}
}
Console.WriteLine(s);
Console.WriteLine(s3);
}
}
}
////////////////////////////////////////////////////////////////////////////////
///////////////

127)Difference of two dates as no of days


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
namespace ConsoleApplication5
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Enter the date");
string str1 = Console.ReadLine();
Console.WriteLine("Enter the date");
string str2 = Console.ReadLine();
DateTime dt1;
DateTime dt2;
int output1 = 0;
bool res = DateTime.TryParseExact(str1, "dd/MM/yyyy", null, System.G
lobalization.DateTimeStyles.None, out dt1);
bool res1 = DateTime.TryParseExact(str2, "dd/MM/yyyy", null, System.
Globalization.DateTimeStyles.None, out dt2);
if (res == true && res1 == true)
{
output1 = dt2.Subtract(dt1).Days;
}
else
{
output1 = -1;
}
Console.WriteLine(output1);
Console.Read();
}
}
}

////////////////////////////////////////////////////////////////////////////////
///////////////////////////////

128)day of next year


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace DayOfNextYear
{
class Class1
{
public static string fun1(string str1)
{
DateTime dt;
DateTime dt1;
string out1 = "";
bool b = DateTime.TryParseExact(str1, "dd/MM/yyyy", null, System.Glo
balization.DateTimeStyles.None, out dt);
if (b == true)
{
dt1 = dt.AddYears(1);
out1=dt1.DayOfWeek.ToString();
}
return out1;

}
}
}
////////////////////////////////////////////////////////////////////////////////
////////////

129)take two strings and a number then return two strings that position in a str
ing
ip= ABC
ip=efg
ip=2
op=BF
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication7
{
class Program
{
static void Main(string[] args)
{
int n;
n = int.Parse(Console.ReadLine());
string[] s = new string[n];
for (int i = 0; i < n; i++)
{
s[i] = Console.ReadLine();
}
int m;
m = int.Parse(Console.ReadLine());
char c;
StringBuilder sb = new StringBuilder();
foreach (string s1 in s)
{
char[] c1 = s1.ToCharArray();
if ((m - 1) < c1.Length)
{
for (int j = 0; j < c1.Length; j++)
{
if (j == (m - 1))
{
c = c1[j];
sb.Append(c);
}

}
}
else
{
c = '$';
sb.Append(c);
}
}
string s2 = sb.ToString();
Console.WriteLine(s2);
}
}
}
OR............................................SHORTER WAY--MY WAY
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Doller
{
class Program
{
static void Main(string[] args)
{
int n = int.Parse(Console.ReadLine());
string[] s = new string[n];
for (int i = 0; i < n; i++)
{
s[i] = Console.ReadLine();
}
int m = int.Parse(Console.ReadLine());
StringBuilder sb = new StringBuilder();

for(int i=0;i<n;i++)
{
if ((m - 1) < s[i].Length)
{
sb.Append(s[i].Substring(m - 1, 1));
}
else
sb.Append("$");
}
Console.WriteLine(sb.ToString());
}
}
}

////////////////////////////////////////////////////////////////////////////////
////////
130) million format
49. milllion format
public static string NumberToWords(int number)
{
if (number == 0)
return "zero";
if (number < 0)
return "minus " + NumberToWords(Math.Abs(number));
string words = "";
if ((number / 1000000) > 0)
{
words += NumberToWords(number / 1000000) + " million ";
number %= 1000000;
}
if ((number / 1000) > 0)
{
words += NumberToWords(number / 1000) + " thousand ";
number %= 1000;
}
if ((number / 100) > 0)
{
words += NumberToWords(number / 100) + " hundred ";
number %= 100;
}
if (number > 0)
{
if (words != "")
words += "and ";
var unitsMap = new[] { "zero", "one", "two", "three", "four", "f
ive", "six", "seven", "eight", "nine", "ten", "eleven", "twelve", "thirteen", "f
ourteen", "fifteen", "sixteen", "seventeen", "eighteen", "nineteen" };
var tensMap = new[] { "zero", "ten", "twenty", "thirty", "forty"
, "fifty", "sixty", "seventy", "eighty", "ninety" };
if (number < 20)
words += unitsMap[number];
else
{
words += tensMap[number / 10];
if ((number % 10) > 0)
words += " " + unitsMap[number % 10];
}
}
return words;
}
static void Main(string[] args)
{
Console.Write("Enter number: ");
int n = Convert.ToInt32(Console.ReadLine());
string op;
op = NumberToWords(n);
Console.WriteLine("Output: "+op);
Console.ReadKey();
}
////////////////////////////////////////////////////////////////////////////////
///////////////

131)//5. Take an integer array (input1) and return an array after keeping number
s starting with input2.
//Input1= {1,4,5,35,36,75,31};
//Input2= 3
//Output={35,36,31}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication94
{
class Program
{
static void Main(string[] args)
{
int[] a = { 1, 4, 5, 35, 36, 75, 31,335 };
int b = 3;
int[] res = returnarr(a, b);
for (int i = 0; i < res.Length; i++)
{
Console.WriteLine(res[i]);
}
Console.ReadLine();
}
public static int[] returnarr(int[] input1, int input2)
{
//string[] a = new string[input1.Length];
// int[] rs = new int[input1.Length];
string k =input2.ToString();
List<int>li = new List<int>();
//List<int> li1 = new List<int>();
for (int i = 0; i < input1.Length; i++)
{
string s = input1[i].ToString();
if (s.StartsWith(k))
{
li.Add(Convert.ToInt32(s));
}
}
return li.ToArray();

}
}
}

////////////////////////////////////////////////////////////////////////////////
//////////////
132)4. Replace the last input2 characters from input1 with input3.
If the length of input1 is less than input2 return -1.
input1=INDIA
input2=3
input3= -
out= IN---
class Program
{
static void Main(string[] args)
{
Console.WriteLine(ReplaceChar("Shilajit",2,'-'));
Console.ReadLine();
}
public static string ReplaceChar(string input1, int input2, char input3)
{
string start = input1.Substring(0, input1.Length - input2);
List<char> li = new List<char>();
foreach (var item in start)
{
li.Add(item);
}
for (int i = 0; i < input2; i++)
{
li.Add(input3);
}
char[] ch = li.ToArray();
return new string(ch);
}
////////////////////////////////////////////////////////////////////////////////
///////////////////
133)Sum of cube of n natural numbers
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication36
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("enter the range");
int input1 = int.Parse(Console.ReadLine());
int sum = 0;
for (int i = 1; i <=input1;i++ )
{
sum = sum + i * i * i;
}
Console.WriteLine(sum);
Console.Read();
}
}
}
////////////////////////////////////////////////////////////////////////////////
///////////////////////

134)
/*1)Find the value I/p Array Size
Data of array in NNNPPPYYY format
find value of addition of YYY with help of PPP
If repeatation then return -1 If special caharacter present then return -2
Example
a)
4
111222333
111222452
111544511
454544545
222
op -> 785
b)
4
111222333
111222333
111544511
454544545
222
op -> -1
c)
4
111@@@333
111222452
111544511
454544545
222
op -> -2*/

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication14
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Enter the size");
int size=Convert.ToInt32(Console.ReadLine());
string [] arr=new string[size];
for (int i = 0; i < size; i++)
{
arr[i] = Console.ReadLine();
}
Console.WriteLine("Enter the PPP");
string PPP = Console.ReadLine();
int result= sourav(arr,PPP);
Console.WriteLine(result);
Console.ReadLine();
}
public static int sourav(string[] arr,string PPP)
{
int sum = 0;
List<string> li = new List<string>();
for (int i = 0; i < arr.Length; i++)
{
if (Array.IndexOf(arr, arr[i]) != Array.LastIndexOf(arr, arr[i])
)
return -1;
char[] ch = arr[i].ToCharArray();
for (int j = 0; j < ch.Length; j++)
{
if (!char.IsDigit(ch[j]))
return -2;
}
}
for (int i = 0; i < arr.Length; i++)
{
if (PPP == arr[i].Substring(3, 3))
{
li.Add(arr[i].Substring(6));
}
}
for (int i = 0; i < li.Count; i++)
{
sum = sum + Convert.ToInt32((li[i]));
}
return sum;
}
}
}
////////////////////////////////////////////////////////////////////////////////
////
135)Remove duplicates elements from integer array and sum all even numbers
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
namespace ConsoleApplication5
{
class Program
{
static void Main(string[] args)
{
int[] input1={1,2,3,4,5,6,5,3,1,9,1,2};
int output1 = 0,f=0;
StringBuilder sb=new StringBuilder();
for (int i = 0; i < input1.Length; i++)
{
for (int j = 0; j < input1.Length; j++)
{
if (input1[i] == input1[j])
{
f = 1;
}
if (f == 0)
{
sb.Append(input1[i]);
}
}
}
string r = sb.ToString();
Console.WriteLine(a);
Console.Read();
}
}
}

//////////////////////////////////////////////////////////////////////////

136) SIMPLE INTEREST:


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net;
namespace ConsoleApplication5
{
class Program
{
static void Main(string[] args)
{
double principal = 1200;
double time = 3.5;
double rate = 9.5;
double simpleinterest=0;
simpleinterest = (principal * time * rate)/100;
Console.WriteLine(simpleinterest);
Console.Read();
}
}
}

////////////////////////////////////////////////////////////////////////////////
///////

137)reverse second string nd insert into the middle of first string


i/p:arun
i/p:saran
o/p:ar(naras)un
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication5
{
class Program
{
public static void Main(string[] args)
{
string input1 = "arun";
string input2 = "saran";
string output1 = " ";
char[] ch = input2.ToCharArray();
Array.Reverse(ch);
string i2=new string(ch);
output1 = input1.Substring(0, input1.Length / 2) + i2 + input1.Subst
ring(input1.Length / 2);
Console.WriteLine(output1);
Console.Read();
}
}
}

////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////
139)take the middle two elements from an even length string.
input=confir
output=nf

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication36
{
class Program
{
static void Main(string[] args)
{
string input1 = "confir";
string output1 = " ";
output1 = input1.Substring(input1.Length / 2 - 1, 2);
Console.WriteLine(output1);
Console.Read();
}
}
}
////////////////////////////////////////////////////////////////////////////////
//////////////////////
140)sum of square of even numbers

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication5
{
class Program
{
static void Main(string[] args)
{
int input1 = 4567;
int output1 = 0,r=0;
while (input1 > 0)
{
r = input1 % 10;
if (r % 2 == 0)
{
output1= output1 + (r * r);
}
input1 = input1 / 10;
}
Console.WriteLine(output1);
Console.Read();
}
}
}
////////////////////////////////////////////////////////////////////////////////
///////////////////
141)Find the number of distinct characters in a given string

Eg: Hello World


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
namespace ConsoleApplication5
{
class Program
{
public static void Main(string[] args)
{
string input1 = "hello world";
string output1 = " ";
StringBuilder sb = new StringBuilder();
foreach (char ch in input1)
{
if (sb.ToString().Contains(ch) && ch != ' ')
{
}
else
{
sb.Append(ch);
}
}
output1 = sb.ToString();
Console.WriteLine(output1);
Console.Read();
}
}
}

////////////////////////////////////////////////////////////////////////////////
/////////////////
142)Intersection of three lists
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication7
{
class Program
{
public List<int> common(List<int> l1, List<int> l2,List<int> l3)
{
List<int> l = new List<int>();
List<int> l4 = new List<int>();
foreach (var i in l1)
{
if (i < 0)
{
l4.Add(-1);
return l4;
}
else if (i > 500)
{
l4.Add(-2);
return l4;
}
else if (i == 0)
{
l4.Add(0);
return l4;
}
}
foreach (var i in l2)
{
if (i < 0)
{
l4.Add(-1);
return l4;
}
else if (i > 500)
{
l4.Add(-2);
return l4;
}
else if (i == 0)
{
l4.Add(0);
return l4;
}
}
foreach (var i in l3)
{
if (i < 0)
{
l4.Add(-1);
return l4;
}
else if (i > 500)
{
l4.Add(-2);
return l4;
}
else if (i == 0)
{
l4.Add(0);
return l4;
}
}
l = (from s in l1 where s%3==0 select s).Intersect(l2).ToList();
l4 = (from s in l3 where s % 3 == 0 select s).Intersect(l).ToList();
return l4;
}
static void Main(string[] args)
{
Program p = new Program();
List<int> l1 = new List<int>();
List<int> l2 = new List<int>();
List<int> l3 = new List<int>();
Console.WriteLine("Enter first list");
for (int i = 0; i < 5; i++)
{
int s1 = Convert.ToInt32(Console.ReadLine());
l1.Add(s1);
}
Console.WriteLine("Enter second list");
for (int i = 0; i < 5; i++)
{
int s1 = Convert.ToInt32(Console.ReadLine());
l2.Add(s1);
}
Console.WriteLine("Enter third list");
for (int i = 0; i < 5; i++)
{
int s1 = Convert.ToInt32(Console.ReadLine());
l3.Add(s1);
}
List<int> li = p.common(l1,l2,l3);
Console.WriteLine("output list");
foreach (var i in li)
{
Console.Write("{0} ", i);
}
Console.ReadLine();
}

}
}
////////////////////////////////////////////////////////////////////////////////
///////////////////
143)Find common elements from 2 given list
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication5
{
class Program
{
static void Main(string[] args)
{
List<int> input1 = new List<int>() { 8, 4, 3, 5, 7, 9, 6, 1,7, 21 };
List<int> input2 = new List<int>() { 8, 3, 8, 11, 9, 15, 1,15 };
List<int> output1 = new List<int>();
output1 = input1.Intersect(input2).ToList();
foreach (var y in output1)
{
Console.WriteLine(y);
}
Console.Read();
}
}
}
////////////////////////////////////////////////////////////////////////////////
//////
144)Check whether the string array contains only numeric values
eg: if i/p:{23,24.5"} =>o/p:1
i/p:{"23","one"} =>o/p:-1
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication5
{
class Program
{
static void Main(string[] args)
{
string[] input1 = { "24", "23.5" };
int output1 = 0,f=0;
foreach (string a in input1)
{
char[] ch = a.ToCharArray();
foreach (char c in ch)
{
if (char.IsDigit(c) || c == '.')
{
f = 0;
}
else
{
f = 1;
break;
}
}
}
if(f==0)
{
output1 = 1;
}
else
{
output1 = -1;
}
Console.WriteLine(output1);
Console.Read();
}
}
}
////////////////////////////////////////////////////////////////////////////////
////////////////////
145)Extract the extension of a file name
eg: i/p:"File.dat" => o/p: "dat"
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication5
{
class Program
{
static void Main(string[] args)
{
string input1 = "file.dat";
string s = input1.Substring(input1.IndexOf(".") + 1);
Console.WriteLine(s);
Console.Read();
}
}
}
////////////////////////////////////////////////////////////////////////////////
////////
146) From the given string form a new word
inputs(string input1 and int input2)
eg: i/p:"california",3 => o/p= "calnia"
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication5
{
class Program
{
static void Main(string[] args)
{
string input1 = "california";
int input2 = 3;
string output;
if (input1.Count() > 2 * input2)
{
output = input1.Substring(0, input2) + input1.Substring(input1.C
ount() - input2);
}
else
output = "-1";
Console.WriteLine(output);
Console.Read();
}
}
}

////////////////////////////////////////////////////////////////////////////////
///////////////////////
147) In a string odd position alphabets into the next alphabet in order
using System;
using System.Collections.Generic;
using System.Text;
using System.Linq;
namespace NumWords
{
class Program
{
static void Main(string[] args)
{
string s = Console.ReadLine();
char[] ch = s.ToCharArray();
StringBuilder sb = new StringBuilder();
string output = "";
int flag = 0;
foreach (char c in ch)
{
if (!(c >= 'a' && c <= 'z'))
{
output += -1;
flag = 1;
break;
}
}
if (flag == 0)
{
foreach (char c in s)
{
int i = Convert.ToInt32(s.IndexOf(c));
if (i % 2 == 0)
{
sb.Append(c);
}
else
sb.Append(Convert.ToChar(c+1));
}
}
Console.WriteLine(sb.ToString());
}
}
}

////////////////////////////////////////////////////////////////////////////////
/////////////////

148) find and print values from list greater than input value:
ip=1 2 3 4 5
ip2=3
op=4 5

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ListFetch
{
class Program
{
public static List<int> FindNumber(List<int> list, int ip)
{
List<int> list1 = new List<int>();
for (int i = 0; i < list.Count; i++)
{
if (list[i] > ip)
{
list1.Add(list[i]);
}
}
return list1;
}

static void Main(string[] args)


{
Console.WriteLine("How many digit you want to entered?");
int n = int.Parse(Console.ReadLine());
List<int> list = new List<int>();
Console.WriteLine("Enter the values:");
for (int i = 0; i < n; i++)
{
list.Add(int.Parse(Console.ReadLine()));
}
Console.WriteLine("Enter the min number");
int ip = int.Parse(Console.ReadLine());
List<int> list1 = FindNumber(list,ip);
Console.WriteLine("Current list contains:");
for (int i = 0; i < list1.Count; i++)
{
Console.WriteLine(list1[i]);
}
}
}
}
////////////////////////////////////////////////////////////////////////////////
///////////////////

149) (series)
i/p=9
o/p=1+3-5+7-9
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace SumToSingleDigit
{
class Program
{
static void Main(string[] args)
{
int num = int.Parse(Console.ReadLine());

int output = UserCode(num);


Console.WriteLine(output);
}
public static int UserCode(int num)
{
int[] arr = new int[num];
int sum = 0;
int k = 0;
for (int i = 1; i <= num; i++)
{
if (i == 1)
{
sum = sum + i;
}
else
{
if (i % 2 != 0)
{
arr[k] = i;
k++;
}
}
}
for (int j = 0; j < k; j = j + 2)
{
sum = sum + arr[j];
}
for (int j = 1; j < k; j = j + 2)
{
sum = sum - arr[j];
}
return sum;
}
}
}
////////////////////////////////////////////////////////////////////////////////
///////////
150) Last Letter of every word in caps and append $
Input= He is out
output= E$S$T$
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace LastLetter
{
class Program
{
public static string lastLetter(string input)
{
string[] s = input.Split(' ');
string output = string.Empty;
int flag = 0;
StringBuilder sb = new StringBuilder();
foreach (string s1 in s)
{
foreach (char s2 in s1)
{
if (!char.IsLetterOrDigit(s2))
{
output = "-1";
flag = 1;
break;
}
if (char.IsDigit(s2))
{
output = "-2";
flag = 1;
break;
}
}
}
if (flag == 0)
{
foreach (string s1 in s)
{
sb.Append(s1.Substring(s1.Length - 1));
sb.Append("$");
}
output = sb.ToString();
output = output.ToUpper();
}
return output;
}
static void Main(string[] args)
{
string input = Console.ReadLine();
string output = lastLetter(input);
Console.WriteLine(output);
}
}
}
OR_____String Manipulation
Input= This is a cat
output= S$S$A$T
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ImageFormat
{
class Program
{
public static string stri(string s)
{
string[] str = s.Split(' ');
StringBuilder sb = new StringBuilder();
for (int j = 0; j < str.Length; j++)
{
char[] ch = str[j].ToCharArray();
for (int i = 0; i < ch.Length; i++)
{
if (char.IsDigit(ch[i]))
{
return "-1";
}
if (!(char.IsLetterOrDigit(ch[i])))
{
return "-2";
}
if (i == ch.Length - 1)
{
sb.Append(char.ToUpper(ch[ch.Length - 1]));
if (str[j] != str[str.Length - 1])
sb.Append('$');
}

}
}
return sb.ToString();
}
static void Main(string[] args)
{
string s = "This is a cat";
Console.WriteLine(stri(s));
Console.ReadKey();
}
}
}
OR
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ImageFormat
{
class Program
{
public static string stri(string s)
{
string[] str = s.Split(' ');
StringBuilder sb = new StringBuilder();
foreach (string i in str)
{
sb.Append(i.Substring(i.Length-1).ToUpper());
sb.Append("$");
}
return sb.ToString().TrimEnd('$');
}
static void Main(string[] args)
{
string s = "This is a cat";
Console.WriteLine(stri(s));
Console.ReadKey();
}
}
}

////////////////////////////////////////////////////////////////////////////////
////////////////////

151)95. Capitalize first letter and rest are in small in a string


ip= hEy mY name is sourAv
op= Hey My Name Is Sourav
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace InitializeCapital
{
class Program
{
public static string Capital(string input)
{
string[] s = input.Split(' ');
string output = string.Empty;
StringBuilder sb = new StringBuilder();
foreach (string s1 in s)
{
sb.Append(s1.Substring(0, 1).ToUpper());
sb.Append(s1.Substring(1).ToLower());
sb.Append(' ');
}
return sb.ToString();
}
static void Main(string[] args)
{
string input = Console.ReadLine();
string output = Capital(input);
Console.WriteLine(output);
}
}
}
////////////////////////////////////////////////////////////////////////////////
////////////

152)Interchange 1st and last letter in a string


ip= Execute
op= executE
ip= BoB
op= No change
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace InterchangeLetter
{
class Program
{
public static string Change(string input)
{
string input1 = input;
StringBuilder sb = new StringBuilder();
int length = input.Length;
string output = string.Empty;
sb.Append(input.Substring(length - 1));
sb.Append(input.Substring(1, length - 2));
sb.Append(input.Substring(0, 1));
if (sb.ToString() == input1)
{
output = "No Change";
}
else
output = sb.ToString();
return output;
}
static void Main(string[] args)
{
string input = Console.ReadLine();
string output = Change(input);
Console.WriteLine(output);
}
}
}
////////////////////////////////////////////////////////////////////////////////
//
153). Count common char in two strings
ip= hey baby
ip= hi hello
op= he
op= 2
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace CountCommonChar
{
class Program
{
static void Main(string[] args)
{
string input1 = Console.ReadLine();
string input2 = Console.ReadLine();
StringBuilder sb = new StringBuilder();
int count = 0;
foreach (char c in input1)
{
if (input2.Contains(c) && !(char.IsWhiteSpace(c)))
{
if (!sb.ToString().Contains(c))
{
sb.Append(c);
count++;
}
}
}
Console.WriteLine(sb.ToString());
Console.WriteLine(count);
}
}
}
////////////////////////////////////////////////////////////////////////////////
//

154) Find the smallest string among a set of string in a list starting with a s
pecified character
ip= 3
sourav
subarna
gourav
s
op= sourav
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ListSmallestString
{
class Program
{
public static string SmallestString(List<string> input, char c)
{
string[] input1 = new string[input.Count];
int i = 0;
string output = string.Empty;
foreach (string s in input)
{
if (s.Substring(0, 1) == c.ToString())
{
input1[i] = s;
i++;
}
}
Array.Resize(ref input1 ,i);
if (input1.Length > 0)
{
int maximum = input1[0].Length;
foreach (string s1 in input1)
{
int n = s1.Length;
if (n <= maximum)
{
maximum = n;
output = s1;
}
}
}
if (input1.Length <= 0)
{
output = "No such Element";
}
return output;
}
static void Main(string[] args)
{
int n = int.Parse(Console.ReadLine());
List<string> input = new List<string>();
for (int i = 0; i < n; i++)
{
input.Add(Console.ReadLine());
}
char c = Convert.ToChar(Console.ReadLine());
string output = SmallestString(input , c);
Console.WriteLine(output);
}
}
}
////////////////////////////////////////////////////////////////////////////////
//////////////////

154) perfect number


public static int[] perfect(int[] a)
{
int sum=0,k=0;
int len = a.Length;
int[] op=new int[len];
//To check if size is 0 or greater than 7.if so return -1
if(len==1 || len>7)
{
Array.Resize(ref op,1);
op[0]=-1;
return op;
}
//To check if array contains repeated elements,if so rerurn -2
var x = (from pr in a select pr).Distinct().Count();
if(x!=len)
{
Array.Resize(ref op, 1);
op[0] = -2;
return op;
}
//To check if array contains negative elements,if so return -3
var y = (from pr in a where pr<0 select pr).Count();
if (y != 0)
{
Array.Resize(ref op, 1);
op[0] = -3;
return op;
}
//exclude perfect elements from the array and reurn int array
for (int i = 0; i < len; i++)
{
sum = 0;
for (int j = 1; j < a[i]; j++)
{
if (a[i] % j == 0)
sum = sum + j;
}
if (sum != a[i])
{
op[k] = a[i];
k++;
}
}
Array.Resize(ref op, k);
int[] str = op.ToArray();
return str;
}
}
}
////////////////////////////////////////////////////////////////////////////////
/////
155)strong number
public static int strong(int a)
{
int r, fact = 1,z,sum=0;
z=a;
while (a > 0)
{
r = a % 10;
fact = 1;
for (int i = 1; i <= r; i++)
{
fact = fact * i;
}
sum = sum + fact;
a=a/10;
}
if (sum == z)
return 1;
else
return -1;

////////////////////////////////////////////////////////////////////////////////
//////////////////
156)middle characters.... eg.this,o/p=hi. only even length strings
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication11
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Enter the string");
string s = Console.ReadLine();
string result = sourav(s);
Console.WriteLine(result);
Console.ReadLine();
}
public static string sourav(string s)
{
if (s.Length % 2 == 0)
{
int length = (s.Length) / 2;
return s.Substring(length - 1, 2);
}
else
return "-1";
}
}
}
////////////////////////////////////////////////////////////////////////////////
//////////////
(xml)
157)using System;
using System.Collections.Generic;
using System.Xml;
class Program
{
static string Getname(string path)
{
XmlDocument obj = new XmlDocument();
obj.Load(path);
XmlNodeList Nodes = obj.SelectNodes("/employees/employee");
List<string> li = new List<string>();
foreach (XmlNode employees in Nodes)
{
string gender = employees.Attributes["gender"].InnerText;
if (gender == "male")
{
li.Add(employees["name"]["fname"].InnerText + ' ' + employees["a
ge"].InnerText + ' ' + employees.Attributes["gender"].InnerText);
}
}
string[] s = li.ToArray();
return string.Join("\n", s);
}
static void Main(string[] args)
{
string n = Getname("C:\\Users\\491531\\Desktop\\New folder (2)\\x11.xml"
);

Console.WriteLine(n);
Console.ReadLine();
}
}
////////////////////////////////////////////////////////////////////////////////
/
158)using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
namespace Age
{
class Program
{
public void age()
{
XmlDocument doc2 = new XmlDocument();
doc2.Load(@"C:\Users\482315\Desktop\xml.xml");
XmlNodeList li=doc2.SelectNodes("students/student/dob");
foreach (XmlNode node in li)
{
DateTime dt = Convert.ToDateTime(node.InnerText);
DateTime dt1 = DateTime.Now;
int age = dt1.Year - dt.Year;
if (age > 20)
{
XmlNode parent = node.ParentNode;
foreach (XmlNode chil in parent)
{
if (chil.Name == "name")
{
Console.WriteLine("{0}:{1}", chil.Name, chil.InnerTe
xt);
}
}
}
Console.WriteLine();
}

}
static void Main(string[] args)
{
Program p1 = new Program();
p1.age();
Console.ReadLine();
}
}
}
////////////////////////////////////////////////////////////////////////////////
////////
159) using System;
using System.Collections.Generic;
using System.Xml;
class Program
{
static string Getname(string path)
{
XmlDocument obj = new XmlDocument();
obj.Load(path);
XmlNodeList Nodes = obj.SelectNodes("/employees/employee");
List<string> li = new List<string>();
foreach (XmlNode employees in Nodes)
{
string gender = employees.Attributes["gender"].InnerText;
if (gender == "male")
{
li.Add(employees["name"]["fname"].InnerText + ' ' + employees["a
ge"].InnerText + ' ' + employees.Attributes["gender"].InnerText);
}
}
string[] s = li.ToArray();
return string.Join("\n", s);
}
static void Main(string[] args)
{
string n = Getname("C:\\Users\\491531\\Desktop\\New folder (2)\\x11.xml"
);

Console.WriteLine(n);
Console.ReadLine();
}
}
////////////////////////////////////////////////////////////////////////////////
//////////////

160)using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
namespace Xml1
{
class Program
{
public void read_data()
{
XmlDocument doc = new XmlDocument();
doc.Load(@"C:\Users\482315\Desktop\xml.xml");
XmlNodeList list = doc.SelectNodes("students/student/address/city");
foreach (XmlNode node in list)
{
char[] ch = node.InnerText.ToCharArray();
if(ch[0]=='k'||ch[0]=='K')
{
XmlNode Parent1 = node.ParentNode;
XmlNode Parent2 = Parent1.ParentNode;
foreach (XmlNode n in Parent2.Attributes)
{
Console.WriteLine("{0}:{1}",n.Name,n.Value);
}
}
Console.WriteLine();
}
}
static void Main(string[] args)
{
Program p = new Program();
p.read_data();
Console.ReadLine();
}
}
}

////////////////////////////////////////////////////////////////////////////////
/////////////////////

161)using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
namespace DueDate
{
class Program
{
public void due()
{
int sum = 0;
XmlDocument doc1=new XmlDocument();
doc1.Load(@"C:\Users\482315\Desktop\xml.xml");
XmlNodeList li1 = doc1.SelectNodes("students/student/due");
foreach (XmlNode n in li1)
{
int due = Convert.ToInt32(n.InnerText);
sum += due;
//XmlNode parent=n.ParentNode;
//foreach (XmlNode s in parent)
//{
// if(s.Name=="Name")
// Console.WriteLine("{0}:{1}",s.Name,s.Value);
//}

}
Console.WriteLine(sum);

}
static void Main(string[] args)
{
Program p1 = new Program();
p1.due();
Console.ReadLine();
}
}
}

////////////////////////////////////////////////////////////////////////////////
/////

162)using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
namespace Westbengal
{
class Program
{
public void read()
{
XmlDocument doc4 = new XmlDocument();
doc4.Load(@"C:\Users\482315\Desktop\xml.xml");
XmlNodeList li4 = doc4.SelectNodes("students/student/address/state")
;
foreach (XmlNode node in li4)
{
if (node.InnerText == "West Bengal")
{
XmlNode parent = node.ParentNode;
XmlNode parent1 = parent.ParentNode;
foreach (XmlNode n in parent1.Attributes)
{
Console.WriteLine("{0}:{1}", n.Name, n.Value);
}
foreach (XmlNode child in parent1.ChildNodes)
{
Console.WriteLine("{0}:{1}",child.Name,child.InnerText);
}
foreach (XmlNode child1 in parent.ChildNodes)
{
Console.WriteLine("{0}:{1}", child1.Name, child1.InnerTe
xt);
}
}
Console.WriteLine();
}
}
static void Main(string[] args)
{
Program p4 = new Program();
p4.read();
Console.ReadLine();
}
}
}

////////////////////////////////////////////////////////////////////////////////
/////////////////

163)Discount senario..............
6)discount scenario
public static double xy(int pa, char c1)
{
int na = 0;
if (c1 != 'm' && c1 != 't')
{
na = -1;
}
else if (pa < 1)
{
na = -2;
}
else if (c1 == 't')
{
if (pa > 1 && pa < 25000)
{
na = Convert.ToInt32(pa - (pa * .05));
}
else if (pa >= 25000 && pa < 50000)
{
na = Convert.ToInt32(pa - (pa * .1));
}
else if (pa >= 50000)
{
na = Convert.ToInt32(pa - (pa * .2));
}
}
else if (c1 == 'm')
{
if (pa > 1 && pa < 25000)
{
na = Convert.ToInt32(pa - (pa * .1));
}
else if (pa >= 25000 && pa < 50000)
{
na = Convert.ToInt32(pa - (pa * .15));
}
else if (pa >= 50000)
{
na = Convert.ToInt32(pa - (pa * .25));
}
}
return na;
}
static void Main(string[] args)
{
int pa1 =0;
char c2='m';
Console.WriteLine(xy(pa1,c2));
Console.ReadKey();
}
////////////////////////////////////////////////////////////////////////////////
//////////////

164)flower scenario
class Program
{
public static int xy(int a,char c1,char c2)
{
int k=0;
if (c1 != 'a' && c1 != 'b')
{
k = -1;
}
else if (a < 1)
{
k = -2;
}
else if (c1 == 'a')
{
if (c2 == 'n')
{
k = 25000 * a;
}
else if (c2 == 'e')
{
k = 25000 * a + 1500;
}
else if (c2 != 'n' && c2 != 'e')
{
k = -3;
}
}
else if (c1 == 'b')
{
if (c2 == 'n')
{
k = 27000 * a;
}
else if (c2 == 'e')
{
k = 27000 * a + 1500;
}
else if (c2 != 'n' && c2 != 'e')
{
k = -3;
}
}
return k;
}
static void Main(string[] args)
{
char ch1='c';
char ch2='n';
int n1=4;
Console.WriteLine(xy(n1,ch1,ch2));
Console.ReadKey();
}
}

////////////////////////////////////////////////////////////////////////////////
////////////////

165)online sales scenario


public static int xy(string s, int n1)
{
int n2=0;
DateTime dt=new DateTime();
bool b = DateTime.TryParseExact(s, "HH:mm:ss",null, System.Globaliza
tion.DateTimeStyles.None, out dt);
int k = Convert.ToInt32(dt.Hour);
if(k>=9 && k<10)
{
n2 = n1 - (n1 * 40) / 100;
}
else if (k >= 10 && k < 11)
{
n2 = n1 - (n1 * 30) / 100;
}
else if (k >= 11 && k < 12)
{
n2 = n1 - (n1 * 20) / 100;
}
else if (k >= 12 && k < 16)
{
n2 = n1 - (n1 * 10) / 100;
}
else if (k >= 16 && k <= 18)
{
n2 = n1 - (n1 * 5) / 100;
}
return n2;
}
static void Main(string[] args)
{
string a = "10:30:00";
int c = 2000;
Console.WriteLine(xy(a,c));
Console.ReadKey();
}
}

////////////////////////////////////////////////////////////////////////////////
/////
166)//Take three inputs from user
//find out the difference between maximum no and minimum no from the three nos
//*If all the three or any of two are same return -1
//*if any no is negative return -2
//Eg: input1=50
//input2=70
//input3=80
//diff=80-50=30
//return diff
public static int xy(int a1, int b1, int c1)
{
int max = 0;
int min = 0;
if (a1 > b1 && a1 > c1)
{
max = a1;
}
else if (b1 > a1 && b1 > c1)
{
max = b1;
}
else if (c1 > b1 && c1 > a1)
{
max = c1;
}
if (a1 < b1 && a1 < c1)
{
min = a1;
}
if (b1 < a1 && b1 < c1)
{
min = b1;
}
if(c1<a1 && c1<b1)
{
min=c1;
}
int dif = max - min;
return dif;
}
static void Main(string[] args)
{
int a = 60;
int b = 90, c = 70;
Console.WriteLine(xy(a,b,c));
Console.ReadKey();
}
}
}
////////////////////////////////////////////////////////////////////////////////
/////////////////
167)ipsita scenario
public static int xy(string a, string b)
{
int k = 0;
if (a == "2w")
{
if (b == "sin")
{
k = 1;
}
else if (b == "retu")
{
k = 2;
}
else if (b == "dai")
{
k = 3;
}
else if (b == "wee")
{
k = 4;
}
else if (b == "mon")
{
k = 5;
}
else
{
k = -2;
}
}
else if (a == "3w")
{
if (b == "sin")
{
k = 6;
}
else if (b == "retu")
{
k = 7;
}
else if (b == "dai")
{
k = 8;
}
else if (b == "wee")
{
k = 9;
}
else if (b == "mon")
{
k = 10;
}
else
{
k = -2;
}
}
else if (a == "lcv")
{
if (b == "sin")
{
k = 11;
}
else if (b == "retu")
{
k = 12;
}
else if (b == "dai")
{
k = 13;
}
else if (b == "wee")
{
k =14;
}
else if (b == "mon")
{
k = 15;
}
else
{
k = -2;
}
}
else if (a == "truck")
{
if (b == "sin")
{
k = 16;
}
else if (b == "retu")
{
k = 17;
}
else if (b == "dai")
{
k = 18;
}
else if (b == "wee")
{
k = 19;
}
else if (b == "mon")
{
k = 20;
}
else
{
k = -2;
}
}
else if (a == "car")
{
if (b == "sin")
{
k = 21;
}
else if (b == "retu")
{
k = 22;
}
else if (b == "dai")
{
k = 23;
}
else if (b == "wee")
{
k = 24;
}
else if (b == "mon")
{
k = 25;
}
else
{
k = -2;
}
}
else
{
k = -1;
}
return k;
}
static void Main(string[] args)
{
string type="3w";
string ttype="dai";
Console.WriteLine(xy(type,ttype));
Console.ReadKey();
}
}
}

///////////////////////////////////////////////////////////////////////////////
/////////////////////

168)batch code senario


Check Batch Code

Write a program which will check if the given input string follows the below for
mat and print the output according to the conditions given below.
1. The format of the string should be 'AAABBCCXXX' where
a. AAA represents the location of the batch
CHN -- Chennai
CBE -- Coimbatore
KOC - Kochi
PUN - Pune
BGL - Bangalore
HYD - Hyderabad
KOL - Kolkata
Business rules:
THe characters 'AAA' should not be other than the above specified values(Only C
apitals). If it is other than these characters, print -1.
b. BB and XXX in the format represents numerals between 0-9. BB Represents the
year and XXX represents the batch code.If other than these are present print -2.
c.CC in the format should be only 'DN', if not print -3.
All the characters in the input string are in upper case. Please make sure you
dont do a spell mistake in the output string.
Example 1:
Input : CHN13DN014
The output string should be in the following format.
DotNet batch 014 has joined in 2013 year and is at Chennai Location
Create a class named UserProgramCode that has the following static method
public static string checkBatch(string input1)

Create a class named Program that accepts the inputs and calls the static metho
d present in the UserProgramCode.

Input and Output Format:


Input consists of a string.
Refer business rules and sample output for formatting specifications.

Sample Input 1 :
CHN13DN014

Sample Output 1 :
DotNet batch 014 has joined in 2013 year and is at Chennai Location
Sample Input 2 :
PUN13DN004

Sample Output 2 :
DotNet batch 004 has joined in 2013 year and is at Pune Location
Sample Input 3 :
BGL14DN014

Sample Output 3 :
DotNet batch 014 has joined in 2014 year and is at Bangalore Location
.............
using System;
class UserProgramCode {
public static string checkBatch(string input1)
{
// fill code here
string ans;
char[] ch = input1.ToCharArray();
string loc = input1.Substring(0, 3);
if (loc != "CHN" && loc != "CBE " && loc != "KOC" && loc != "PUN" && lo
c != "BGL" && loc != "HYD" && loc != "KOL")
{
ans = "-1";
return ans;
}
string yr = input1.Substring(3, 2);
string bat = input1.Substring(7);
string pr=null;
if(!(char.IsDigit(ch[3]) && char.IsDigit(ch[4]) && char.IsDigit(ch[7]) &
& char.IsDigit(ch[8]) && char.IsDigit(ch[9])))
{
ans = "-2";
return ans;
}
string dn=input1.Substring(5,2);
if(!(dn=="DN"))
{
ans = "-3";
return ans;
}
if(loc=="CHN")
pr="Chennai";
else if(loc=="CBE")
pr="Coimbatore";
else if(loc=="KOC")
pr="Kochi";
else if(loc=="PUN")
pr="Pune";
else if(loc=="BGL")
pr="Bangalore";
else if(loc=="HYD")
pr="Hyderabad";
else if(loc=="KOL")
pr="Kolkata";
ans="DotNet batch "+bat+" has joined in 20"+yr+" year and is at "+pr+" L
ocation";
return ans;
}
}

////////////////////////////////////////////////////////////////////////////////
//////////////////////
169)car parking senario
public static double xy(string s1, string s2)
{
double output=0.0;
double h;
DateTime dt=new DateTime();
DateTime dt1=new DateTime();
bool b1=DateTime.TryParseExact(s1,"yyyy/MM/dd hh:mm:ss tt",null,Syst
em.Globalization.DateTimeStyles.None,out dt);
bool b2 = DateTime.TryParseExact(s2, "yyyy/MM/dd hh:mm:ss tt", null,
System.Globalization.DateTimeStyles.None, out dt1);
if (b1 == false || b2 == false)
{
output = -1;
}
else if (dt > dt1)
{
output = 1;
}
else
{
h = Math.Ceiling(dt1.Subtract(dt).TotalHours);
if (h > 24)
{
output = -3;
}
else if (h < 3)
{
output = -2;
}
else if (h > 3 && h < 24)
{
output = 2 + (.50 * (h - 3));
}
}
return output;
}
static void Main(string[] args)
{
string s1 = "1991/09/12 06:45:56 am";
string s2 = "1991/09/12 11:45:56 am";
Console.WriteLine(xy(s1,s2));
Console.ReadKey();
}
////////////////////////////////////////////////////////////////////////////////
///////////////
170)Employee senario
using System;
class UserProgramCode {
public static int[] empDailyAllowance(int[] input1)
{
int bp = 350, fa = 100, ta = 50;
int i = 0,c1=0,c2=0,c3=0;
int[] output=new int[input1.Length];
foreach(int n in input1)
{
if (n < 0)
c1++;
}
if (input1.Length % 2 != 0)
{
c3++;
}
else if (input1.Length >= 11)
{
c3++;
}
else
{
for (int j = 0; j < input1.Length ; j=j+2)
{
for (int k = j + 2; k < input1.Length ; k=k+2)
{
if (input1[j] == input1[k])
c2++;
}
}
}
if(c1!=0)
{
int[] output1 = {-1};
return output1;
}
else if (c2 != 0)
{
int[] output2 = {-2};
return output2;
}
else if (c3 != 0)
{
int[] output3 = { -3 };
return output3;
}
else
{
for (i = 0; i < input1.Length-1; i=i+2)
{
output[i] = input1[i];
output[i + 1] = bp * input1[i + 1] + fa + ta;
}
return output;
}
}
}

////////////////////////////////////////////////////////////////////////////////
//////////////
171) insurance senario
using System;
class UserProgramCode
{
public static void InsuranceGuide(char health,int age,char gender,char locatio
n)
{
//Fill your code here
if (health == 'E')
{
if (age >= 25 && age <= 35)
{
if (location == 'C')
{
if (gender == 'M')
{
Console.WriteLine("4");
Console.WriteLine("200000");
}
else
{
Console.WriteLine("3");
Console.WriteLine("100000");
}
}
else
{
Console.WriteLine("The person cannot be insured");
}
}
else
{
Console.WriteLine("Age limit Exceeded");
}

}
else
{
if (age >= 25 && age <= 35)
{
if(location == 'V')
{
if (gender == 'M')
{
Console.WriteLine("6");
Console.WriteLine("10000 ");
}
}
}
else
{
Console.WriteLine("The person cannot be insured");
}
}
}

------------------------------------------------------------
using System;

class Program
{
public static void Main( string[] args )

{
char health=Convert.ToChar(Console.ReadLine());
int age=Convert.ToInt32(Console.ReadLine());
char gender=Convert.ToChar(Console.ReadLine());
char location=Convert.ToChar(Console.ReadLine());
UserProgramCode.InsuranceGuide(health,age,gender,location);
}
}
////////////////////////////////////////////////////////////////////////////////
//////////////////
172) electric bill
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication24
{
class Program
{
public int ab(int a, string[] s)
{
string k2="";
int k=0,f1=0,f2=0;
double out1 = 0;
StringBuilder sb=new StringBuilder();
StringBuilder sb1=new StringBuilder();
foreach (string s1 in s)
{
try
{
k = int.Parse(s1.Substring(0, s1.Length - 1));
}
catch
{
return -4;
}
k2 = s1.Substring(s1.Length - 1, 1);
if (k <= 0 || k > 999)
return -1;
if (k > 0 && k < 999)
{
f2++;
}
if (k2 == "N" || k2 == "E" || k2 == "P")
{
f1++;
}
if (k2 != "N" && k2 != "E" && k2 != "P")
return -2;
}
foreach (string s6 in s)
{
if (f1 == a && f2 == a)
{
if (s6.EndsWith("N"))
{
string d1 = s6.Substring(0, s6.Length - 1);
int d2 = int.Parse(d1);
if (d2 < 100)
out1 = out1 + d2 * 4;
else if (d2 > 100 && d2 <= 300)
out1 = out1 + d2 * 4.5;
else if (d2 > 300 && d2 <= 500)
out1 = out1 + d2 * 4.75;
else if (d2 > 500)
out1 = out1 + d2 * 5;
}
else if (s6.EndsWith("E"))
{
string d1 = s6.Substring(0, s6.Length - 1);
int d2 = int.Parse(d1);
if (d2 < 100)
out1 = out1 + d2 * 4+300;
else if (d2 > 100 && d2 <= 300)
out1 = out1 + d2 * 4.5+300;
else if (d2 > 300 && d2 <= 500)
out1 = out1 + d2 * 4.75+300;
else if (d2 > 500)
out1 = out1 + d2 * 5+300;
}
else if (s6.EndsWith("P"))
{
string d1 = s6.Substring(0, s6.Length - 1);
int d2 = int.Parse(d1);
if (d2 < 100)
out1 = out1 + d2 * 4+450;
else if (d2 > 100 && d2 <= 300)
out1 = out1 + d2 * 4.5+450;
else if (d2 > 300 && d2 <= 500)
out1 = out1 + d2 * 4.75+450;
else if (d2 > 500)
out1 = out1 + d2 * 5+450;
}
}
}
int kk = Convert.ToInt32(out1);
return kk;
}
static void Main(string[] args)
{
Program p = new Program();
int h = 3;
string[] h1 = { "250E", "156N", "776P" };
Console.WriteLine(p.ab(h,h1));
Console.ReadKey();
}
}
}

////////////////////////////////////////////////////////////////////////////////
///////
173)Leader number
Find leader
class UserProgramCode
{
public static List<int> findLeadersArray(int[] input)
{
List<int> l= new List<int>();
List<int> l1 = new List<int>();
for (int i = 0; i < input.Length; i++)
{
if (input[i] < 0)
{
l.Add(-1);
return l;
}
}
if (input.Length<2 || input.Length>10)
{
l.Add(-2);
return l;
}
for (int i = 0; i < input.Length; i++)
{
for (int j = i+1; j < input.Length; j++)
{
if (input[i]==input[j])
{
l.Add(-3);
return l;
}
}
}
l.Add(input[input.Length - 1]);
int temp = 0;
for (int i = 0; i < input.Length; i++)
{
for (int j = i+1; j < input.Length; j++)
{
if (input[i] > input[j])
{
temp = input[i];
}
else
{
temp = 0;
break;
}
}
if (temp != 0)
{
l.Add(temp);
}
temp = 0;
}
l.Sort();
return l;
}
class Program
{
public static void Main( string[] args )
{
int size;
List<int> opli = new List<int>();
size = Convert.ToInt32(Console.ReadLine());
int[] arr = new int[size];
for(int i=0;i<size;i++)
{
arr[i] = Convert.ToInt32(Console.ReadLine());
}
opli = UserProgramCode.findLeadersArray(arr);
for(int i=0;i<opli.Count;i++)
{
Console.WriteLine(opli[i]);
}
Console.ReadLine();
}
}

////////////////////////////////////////////////////////////////////////////////
//////////////////

174) lottery
public static int getLottery(int input1,int input2,int input3)
{
int n,sum=0;
if (input1 <= 0 || input2 <= 0 || input3 <= 0)
{
n = -1;
return n;
}
else if (input1 > 100 || input2 > 100 || input2 > 100)
{
n = -2;
return n;
}
else if (input1 % 17 == 0 && input2 % 17 == 0 && input3 % 17 == 0)
{
n = -3;
return n;
}
else
{
if (input1 % 17 == 0)
{
sum = input2 + input3;
}
else if (input2 % 17 == 0)
{
sum = input3 + input1;
}
else if (input3 % 17 == 0)
{
sum = input1 + input2;
}
}
return sum;
}
}
//////////////////////////////////////////////////////////////////////////////
///////////////

175)marks senario
Given a string array Input (Input 1) containing Student name and percentage of m
arks in the below format Input = {StudentName1, Mark1, StudentName2, Mark2, Stud
entName3, Mark3,......etc},
write a program to determine the student grade based on below condition, and pri
nt the output in the below format.

AAA has scored BBB marks with CCC scores

where AAA - Input StudentName (Input 2), BBB - Mark and CCC - Grade in Upper cas
e.
Grade calculation:
If the mark is greater than or equal to 80, then OUTSTANDING
If the mark is less than 80 and greater than or equal to 60, then GOOD
If the mark is less than 60 and greater than or equal to 50, then AVERAGE
If the mark is less than 50, then FAIL
Business rule:
1) If any of the StudentName in Input1 or Input2 contains any special characters
, then print Invalid Input .
2) If the Input2 string value is not present in Input1 array, then print Invalid
Student
3) If the Input1 array length is odd, then print No corresponding Student or Mark

Create a class named UserProgramCode that has the following static method
public static string studentScore(string[] input1, string input2)
Create a class named Program that accepts the inputs and calls the static method
present in the UserProgramCode.
Input and Output Format:
The first line of the input consists of an integer, n that corresponds to the nu
mber of elements in the input array.
The next 'n' lines of input consist of elements in the input array.
The next line of the input consists of a string that corresponds to the student
name.
Refer business rules and sample output for formatting specifications.
Sample Input 1 :
4
Ram
55
Vignesh
89
Vignesh

Sample Output 1 :
Vignesh has scored 89 marks with OUTSTANDING grade
Sample Input 2 :
4
Anil
76
Sunil
68
Raja
Vignesh

Sample Output 2 :
No corresponding Student or Mark

class Program
{
public static string fun(string[] s, string i2)
{
string[] str = s;
string out1 = "";
int marks = 0, f1 = 0, f2 = 0;
if (str.Length % 2 == 0)
{
for (int i = 0; i < str.Length; i++)
{
if (i % 2 == 0)
{
foreach (char c in str[i])
{
if (char.IsLetter(c))
{
f1 = 1;
}
else
{
f1 = -1;
}
}
foreach (char c1 in i2.ToCharArray())
{
if (char.IsLetter(c1))
{
f2 = 1;
}
else
{
f2 = -1;
}
}
if (f1 == 1 && f2 == 1)
{
if (s[i] == i2)
{
marks = Int32.Parse(str[i + 1]);
if (marks >= 80)
out1 = s[i] + " has scored " + str[i + 1] +
" marks with OUTSTANDING grade";
if (marks < 80 && marks >= 60)
out1 = s[i] + " has scored " + str[i + 1] +
" marks with GOOD grade";
if (marks < 60 && marks >= 50)
out1 = s[i] + " has scored " + str[i + 1] +
" marks with AVERAGE grade";
if (marks < 50)
out1 = "fail";
}
else
{
out1 = "invalid student";
}
}
else if (f1 == -1 || f2 == -1)
{
out1 = "invalid input";
}
}
}
}
else
{
out1 = "no marks or student";
}

return out1;

}
static void Main(string[] args)
{
int size = Int32.Parse(Console.ReadLine());
string[] str = new string[size];
for (int i = 0; i < size; i++)
{
str[i] = Console.ReadLine();
}
string input2 = Console.ReadLine();
Console.WriteLine(Program.fun(str, input2));

}
}
}
////////////////////////////////////////////////////////////////////////////////
////

176) online scenario


public static int xy(string s, int n1)
{
int n2=0;
DateTime dt=new DateTime();
bool b = DateTime.TryParseExact(s, "HH:mm:ss",null, System.Globaliza
tion.DateTimeStyles.None, out dt);
int k = Convert.ToInt32(dt.Hour);
if(k>=9 && k<10)
{
n2 = n1 - (n1 * 40) / 100;
}
else if (k >= 10 && k < 11)
{
n2 = n1 - (n1 * 30) / 100;
}
else if (k >= 11 && k < 12)
{
n2 = n1 - (n1 * 20) / 100;
}
else if (k >= 12 && k < 16)
{
n2 = n1 - (n1 * 10) / 100;
}
else if (k >= 16 && k <= 18)
{
n2 = n1 - (n1 * 5) / 100;
}
return n2;
}
static void Main(string[] args)
{
string a = "10:30:00";
int c = 2000;
Console.WriteLine(xy(a,c));
Console.ReadKey();
}
}

////////////////////////////////////////////////////////////////////////////////
////////////////

178) revised salary


using System;
class UserProgramCode
{
public static int revisedSalary(int[] arr)
{
int EmployeeId=arr[0];
int Grade=arr[1];
int Rating=arr[2];
int CurrentSalary=arr[3];
if(!(EmployeeId>=100000 && EmployeeId<=500000))
{
return -1;
}
if(!(Grade==1||Grade==2||Grade==3))
{
return -2;
}
if(!(Rating==1||Rating==2|Rating==3))
{
return -3;
}
if (CurrentSalary<0||CurrentSalary>500000)
{
return -4;
}

double newsal=0;
if (Grade == 1)
{
if(Rating==1)
{
newsal = (0.15 * CurrentSalary + CurrentSalary);
}
if (Rating ==2)
{
newsal = (0.10 * CurrentSalary + CurrentSalary);
}
if (Rating == 3)
{
newsal = (0.05 * CurrentSalary + CurrentSalary);
}
}
else if (Grade == 2)
{
if (Rating == 1)
{
newsal = (0.10 * CurrentSalary + CurrentSalary);
}
if (Rating == 2)
{
newsal = (0.05 * CurrentSalary + CurrentSalary);
}
if (Rating == 3)
{
newsal = (0.02 * CurrentSalary + CurrentSalary);
}
}
else if (Grade == 3)
{
if (Rating == 1)
{
newsal = (0.07 * CurrentSalary + CurrentSalary);
}
if (Rating == 2)
{
newsal = (0.05 * CurrentSalary + CurrentSalary);
}
if (Rating == 3)
{
newsal = (0.02 * CurrentSalary + CurrentSalary);
}
}
return (int)newsal;
}
}

////////////////////////////////////////////////////////////////////////////////
//////////////
179) senario employee grade
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Scenario2
{
class Program
{
public static int salary(int[] str)
{
int out1=0;
int x = 0;
// for (int i = 0; i < str.Length; i++)
//{
if (str[0] > 100000 && str[0] < 500000)
{
if (str[1] == 1 || str[1] == 2 || str[1] == 3)
{
if (str[2] == 1 || str[2] == 2 || str[2] == 3)
{
if (str[3] > 1 && str[3] < 50000)
{
if (str[1] == 1)
{
if (str[2] == 1)
{
x = str[3];
out1 = (int)(x + x * 0.15);
}
if (str[2] == 2)
{
x = str[3];
out1 = (int)(x + x * 0.10);
}
if (str[2] == 3)
{
x = str[3];
out1 = (int)(x + x * 0.07);
}
}
if (str[1] == 2)
{
if (str[2] == 1)
{
x = str[3];
out1 = (int)(x + x * 0.10);
}
if (str[2] == 2)
{
x = str[3];
out1 = (int)(x + x * 0.07);
}
if (str[2] == 3)
{
x = str[3];
out1 = (int)(x + x * 0.05);
}
}
if (str[1] == 3)
{
if (str[2] == 1)
{
x = str[3];
out1 = (int)(x + x * 0.07);
}
if (str[2] == 2)
{
x = str[3];
out1 = (int)(x + x * 0.05);
}
if (str[2] == 3)
{
x = str[3];
out1 = (int)(x + x * 0.02);
}
}
}
else
{
out1 = -4;
}
}
else
{
out1 = -3;
}
}
else
{
out1 = -2;
}
}
else
{
out1 = -1;
}
//}
return out1;
}
static void Main(string[] args)
{
int size = Int32.Parse(Console.ReadLine());
int[] s = new int[size];
for (int i = 0; i < size; i++)
{
s[i] = Int32.Parse(Console.ReadLine());
}
Console.WriteLine(Program.salary(s));
}
}
}

////////////////////////////////////////////////////////////////////////////////
////////////////////

180) student marks senario

Student mark -> input- 5 integers


if avg>=60 ->First class
if avg>=50 &&avg<=59 ->Second Class
if avg>=40 &&avg<=49 -> Third Class
less than 40 -> failed
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
namespace ConsoleApplication5
{
class Program
{
static void Main(string[] args)
{
int[] input1 = { 45, 65, 75, 87, 90 };
string output1=" ";
double a = input1.Average();
if(a>=60)
{
output1="First class";
}
if(a>=50 &&a<=59)
{
output1="Second Class";
}
if(a>=40 &&a<=49)
{
output1="Third Class";
}
if(a<=40)
{
output1="fail";
}
Console.WriteLine(output1);
Console.Read();
}
}
}

////////////////////////////////////////////////////////////////////////////////
//////////

181) vat senario


Calculate VAT%
Input= character and integer input
If product = M
Vat= 5
V
Vat=12
C"
Vat=6.25
D
Vat=6
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication36
{
class Program
{
static void Main(string[] args)
{
double input1=1000;
double output1;
double percent;
double vat;
char input2='M';
switch (input2)
{
case 'M':
percent = 5;
vat = percent / 100;
output1 = input1 * (1 + vat);
Console.WriteLine(output1);
break;
case 'V':
percent = 12;
vat = percent / 100;
output1 = input1 * (1 + vat);
Console.WriteLine(output1);
break;
case 'C':
percent = 6.25;
vat = percent / 100;
output1 = input1 * (1 + vat);
Console.WriteLine(output1);
break;
case 'D':
percent = 7;
vat = percent / 100;
output1 = input1 * (1 + vat);
Console.WriteLine(output1);
break;
default:
output1 = -1;
Console.WriteLine(output1);
break;
}
Console.Read();
}
}
}

////////////////////////////////////////////////////////////////////////////////
///////////////

182) Calculate take home salary where basic salary, PF amount and medical insura
nce will be given.
Take Home Salary=salary-PF-medicalInsurance
PF
for sal<15000---750
sal between 15000 and 22000---850
sal between 22000 to 30000--925
salary above 30000--1000
medical insurance for all the employees is 678
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication36
{
class Program
{
static void Main(string[] args)
{
int input1 = 22000;
int output1;
int pf;
int mi = 678;
if (input1 < 15000)
{
pf = 750;
output1 = input1 - pf - mi;
Console.WriteLine(output1);
}
else if (input1 >= 15000 && input1 <= 22000)
{
pf = 850;
output1 = input1 - pf - mi;
Console.WriteLine(output1);
}
else if (input1 > 22000 && input1 <= 30000)
{
pf = 925;
output1 = input1 - pf - mi;
Console.WriteLine(output1);
}
else
{
pf = 1000;
output1 = input1 - pf - mi;
Console.WriteLine(output1);
}
Console.Read();
}
}
}

////////////////////////////////////////////////////////////////////////////////
/////////////
183) electric bill 2
electto/ electric bill
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication2
{
class Program
{
static void Main(string[] args)
{
double output = 0;
double price = Convert.ToDouble(Console.ReadLine());
string type = Console.ReadLine();
double discount, discrate, bill = 0.0;

if (!(type == "T" || type == "t") || !(type == "M" || type == "m") |


| !(type == "tm" || type == "TM"))
{
bill = -1;
}
if (price <= 0)
{
bill = -2;
}

else
{
if (type == "T" || type == "t")
{
if (price > 0 && price <= 25000)
{
discrate = 5;
discount = price * (discrate / 100);
bill = price - discount;
}
if (price > 25000 && price <= 50000)
{
discrate = 10;
discount = price * (discrate / 100);
bill = price - discount;
}
if (price > 50000)
{
discrate = 15;
discount = price * (discrate / 100);
bill = price - discount;
}

}
else if (type == "M" || type == "m")
{
if (price > 0 && price <= 25000)
{
discrate = 10;
discount = price * (discrate / 100);
bill = price - discount;
}
if (price > 25000 && price <= 50000)
{
discrate = 20;
discount = price * (discrate / 100);
bill = price - discount;
}
if (price > 50000)
{
discrate = 30;
discount = price * (discrate / 100);
bill = price - discount;
}
}
else if (type == "tm" || type == "TM")
{
char[] arr = type.ToCharArray();
double bill1 = 0, bill2 = 0;
foreach (var c in arr)
{
if (c == 'T' || c == 't')
{
if (price > 0 && price <= 25000)
{
discrate = 5;
discount = price * (discrate / 100);
bill = price - discount;
}
if (price > 25000 && price <= 50000)
{
discrate = 10;
discount = price * (discrate / 100);
bill = price - discount;
}
if (price > 50000)
{
discrate = 15;
discount = price * (discrate / 100);
bill = price - discount;
}
bill1 = bill;
}
else if (c == 'M' || c == 'm')
{
if (price > 0 && price <= 25000)
{
discrate = 10;
discount = price * (discrate / 100);
bill = price - discount;
}
if (price > 25000 && price <= 50000)
{
discrate = 20;
discount = price * (discrate / 100);
bill = price - discount;
}
if (price > 50000)
{
discrate = 30;
discount = price * (discrate / 100);
bill = price - discount;
}
bill2 = bill;
}
}
bill = bill1 + bill2;
}
}

output = bill;
Console.WriteLine(output);
Console.Read();

}
}
}

////////////////////////////////////////////////////////////////////////////////
////////////////
181)5. largest in a given number
(eg.756....
ans:7)
static void Main(string[] args)
{
int n=int.Parse(Console.ReadLine());
int x = 0, r;
while (n > 0)
{
r = n % 10;
if (r > x)
{
x = r;
}
n = n / 10;
}
Console.WriteLine(x);
Console.ReadLine();
}
}
}

////////////////////////////////////////////////////////////////////////////////
//////////////////////

182)EMI senario

EMI shceme..
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
using System.Text.RegularExpressions;
public static int inst(string dob, int month)
{
if ((month != 12) && (month != 24) && (month != 36) && (month != 48)
)
{
return -2;
}
DateTime dt1;
int inst=0;
double amount1;
bool i = DateTime.TryParseExact(dob, "yyyy-MM-dd", null, System.Glob
alization.DateTimeStyles.None, out dt1);
if (i == true)
{
int year = DateTime.Now.Year - dt1.Year;
int mont = DateTime.Now.Month - dt1.Month;
string maxdate = "2022-06-06";
DateTime dt2 = Convert.ToDateTime(maxdate);
DateTime dt3=DateTime.Now.Date;
DateTime dt4 = dt3.AddMonths(month);
if(dt4>dt2)
{
return -4;
}
if (mont < 0)
{
year = year - 1;
mont = mont + 12;
}
if (year <= 22)
{
amount1 =(double) 200000*1.03;
inst = (int)amount1 / month;
}
if (year > 22 && year<=45)
{
amount1 = (double)300000 * 1.05;
inst = (int)amount1 / month;
}
if (year > 45 && year <= 100)
{
amount1 = (double)500000 * 1.07;
inst = (int)amount1 / month;
}
return inst;
}
else
return -1;
}

////////////////////////////////////////////////////////////////////////////////
/////////

183)subset of two
Subset program- count sum of 2 digit=third digit:
ip= 4
1 2 3 5
op= 123
235
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace IntersectEx
{
class Program
{
public static int[] yuk(int[] b,int a)
{
int[] n = new int[10];
for(int i=0;i<a;i++)
{
if(b[i]<0)
{
n[0]=-1;
Array.Resize(ref n,1);
return n;
}
}
int k = 0, p = 0;
var q = (from p1 in b from p2 in b from p3 in b where p1
!= p2 && p2 != p3 && p3 != p1 && p1+p2==p3 && p2+p1==p3 select string.Concat(p1
, p2, p3)).Distinct();
string[] m=new string[10];
foreach (var i in q)
{
char[] j = i.ToCharArray();
Array.Sort(j);
string s = new string(j);
m[k] = s;
k++;
}
Array.Resize(ref m,k);
var z = (from pr in m select pr).Distinct();
foreach (var x in z)
{
n[p] =Convert.ToInt32(x);
p++;
}
Array.Resize(ref n, p);
return n;
}
static void Main(string[] args)
{
int a;
int i;
Console.WriteLine("enter the set size");
a = Convert.ToInt32(Console.ReadLine());
int[] b = new int[a];
for (i = 0; i < a; i++)
{
b[i] = Convert.ToInt32(Console.ReadLine());
}
int[] c = yuk(b, a);
foreach (var s in c)
{
Console.WriteLine(s);
}
Console.ReadKey();
}
}
}
OR
to count the occurance
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace IntersectEx
{
class Program
{
public static int yuk(int[] b,int a)
{
int[] n = new int[10];
int k = 0, p = 0;
for(int i=0;i<a;i++)
{
if(b[i]<0)
{
n[0]=-1;
Array.Resize(ref n,1);
return p;
}
}
var q = (from p1 in b from p2 in b from p3 in b where p1 != p2 && p2
!= p3 && p3 != p1 && p1+p2==p3 && p2+p1==p3 select string.Concat(p1, p2, p3)).D
istinct();
string[] m=new string[10];
foreach (var i in q)
{
char[] j = i.ToCharArray();
Array.Sort(j);
string s = new string(j);
m[k] = s;
k++;
}
Array.Resize(ref m,k);
var z = (from pr in m select pr).Distinct();
foreach (var x in z)
{
n[p] =Convert.ToInt32(x);
p++;
}
Array.Resize(ref n, p);
return p;
}
static void Main(string[] args)
{
int a;
int i;
Console.WriteLine("enter the set size");
a = Convert.ToInt32(Console.ReadLine());
int[] b = new int[a];
for (i = 0; i < a; i++)
{
b[i] = Convert.ToInt32(Console.ReadLine());
}
int c = yuk(b, a);
}
}
}
////////////////////////////////////////////////////////////////////////////////
//////////////////

184) image file format


Display the image file format from the input string(name of the image file mura
li)
static void Main(string[] args)
{
string ip, op;
ip = Console.ReadLine();
op = UserCode.DispImg(ip);
if (op == "-1")
{
Console.WriteLine("image format not given");
}
else if (op == "-2")
{
Console.WriteLine("Invalid Image Format");
}
else
{
Console.WriteLine(op);
}
Console.ReadKey();
}
UserCode:
public static string DispImg(string ip)
{
string[] ou;
string op = string.Empty;
string[] ch = new string[] { "jpeg", "jpg", "jif", "jfif", "png", "g
if", "pdf", "tif", "tiff", "jp2", "jpx", "j2k", "j2c", "fpx", "pcd" };
if (ip.Contains('.'))
{
ou = ip.Split('.');
foreach (string item in ch)
{
if (ou[1] == item)
{
op = ou[1];
break;
}
else
{
op = "-2";
}
}
}
else
{
op = "-1";
return op;
}
return op;
}

////////////////////////////////////////////////////////////////////////////////
///////////

185) train booking senario

train booking
public static String Berth_type(String s1, String s2, String s3)
{
String b1="", b2="", b3="";
int m1, m2, m3,temp=0;
String res = "";
try
{
m1 = Convert.ToInt32(s1);
m2 = Convert.ToInt32(s2);
m3 = Convert.ToInt32(s3);
if (m1 < 0 || m2 < 0 || m3 < 0)
{
throw new Exception();
}
}
catch
{
res = "Invalid Seat No.";
return res;
}
int r1 = m1 % 8;
int r2 = m2 % 8;
int r3 = m3 % 8;
if ((r1 == 3 || r1 == 5 ))
{
b1 = "Lower";
}
if(( r2 == 3 || r2 == 5))
{
b2 = "Lower";
}
if ((r3 == 3 || r3 == 5))
{
b3 = "Lower";
}
if (b2 == "Lower")
{
res = "Grandfather got Lower seat";
return res;
}
else if (b2 != "Lower")
{
if (b1 == "Lower")
{
res="Your seat has been swapped from "+m2+" to "+m1;
temp = m1;
m1 = m2;
m2 = temp;
return res;
}
else if (b3 == "Lower")
{
res = "Your seat has been swapped from " + m2 + " to " + m3;
temp = m3;
m3 = m2;
m2 = temp;
return res;
}
else
{
res = "Sorry your request can not be processed....";
return res;
}
}
return res;
}
static void Main(string[] args)
{
String s1 = Console.ReadLine();
String s2 = Console.ReadLine();
String s3 = Console.ReadLine();
String r = Berth_type(s1, s2, s3);
Console.WriteLine(r);
Console.ReadKey();
}
}
}

////////////////////////////////////////////////////////////////////////////////
///////////

186)median
Main:
static void Main(string[] args)
{
int[] ip = new int[10];
int n;
int[] op = new int[10];
n = Convert.ToInt32(Console.ReadLine());
for (int i = 0; i < n; i++)
{
ip[i] = Convert.ToInt32(Console.ReadLine());
}
Array.Resize(ref ip,n);
op = UserCode.Median(ip);
foreach (int item in op)
{
Console.WriteLine(item);

}
Console.ReadKey();
}
UserCode:
public static int[] Median(int[] ip)
{
int[] oup = new int[10];
int size = ip.Length;int j = 0;
if (size == 0)
{
oup[j] = -1;
Array.Resize(ref oup, j+1);
return oup;
}
else
{
foreach (int item in ip)
{
if (item < 0)
{
oup[j] = -2;
Array.Resize(ref oup, j+1);
return oup;
}
}
}
if (size % 2 == 0)
{
for ( j = 0; j < 2; j++)
{
oup[j] = ip[(size / 2) + (-1 + j)];
}
Array.Resize(ref oup, j);
}
else
{
oup[j] = ip[(size / 2)];
Array.Resize(ref oup, j + 1);
}
return oup;
}

////////////////////////////////////////////////////////////////////////////////
///////
187). Count common char in two strings
ip= hey baby
ip= hi hello
op= he
op= 2
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace CountCommonChar
{
class Program
{
static void Main(string[] args)
{
string input1 = Console.ReadLine();
string input2 = Console.ReadLine();
StringBuilder sb = new StringBuilder();
int count = 0;
foreach (char c in input1)
{
if (input2.Contains(c) && !(char.IsWhiteSpace(c)))
{
if (!sb.ToString().Contains(c))
{
sb.Append(c);
count++;
}
}
}
Console.WriteLine(sb.ToString());
Console.WriteLine(count);
}
}
}
////////////////////////////////////////////////////////////////////////////////
////////////////

189) health care senario..


1)Health is excellent and age=[25,35] and location is city and
gender is male,then premium is 4 per thousand and amount for facilities
taken is 2 lakh
2) if in above scenario gender is female then premium is 3 per thousand
and amount for facilities taken is 1 lakh
3) if age is above 60 then not eligible for voting
4)the person can't be insured otherwise
using System;

class UserProgramCode
{
public static void InsuranceGuide(char health,int age,
char gender,char location)
{
int premium,amount;
if (health == 'E' && age>=25 && age<=35 && location=='C' && gender=='M')
{
premium = 4;
amount = 200000;
Console.WriteLine(premium);
Console.WriteLine(amount);
}
else if (health == 'E' && age >= 25 && age <= 35 && location == 'C' && gen
der == 'F')
{
premium = 3;
amount = 100000;
Console.WriteLine(premium);
Console.WriteLine(amount);
}
else if (health == 'P' && age >= 25 && age <= 35 && location == 'V' && gen
der == 'M')
{
premium = 6;
amount = 100000;
Console.WriteLine(premium);
Console.WriteLine(amount);
}
else if (age > 60)
{
Console.WriteLine("Age limit Exceeded");
}
else
{
Console.WriteLine("The person cannot be insured");
}
}
}

////////////////////////////////////////////////////////////////////////////////
////////////////////

190) cattle gaze or cow problem

using System;
class Program
{
public static void Main(string[] args)
{
int n;
n = int.Parse(Console.ReadLine());
Console.WriteLine(UserProgramCode.calculateArea(n));
}
}
public class UserProgramCode
{
public static double calculateArea(double n)
{
double area,output;
area =(3.14 * n * n);
output = Math.Round(area, 2);
return output;
}
}

////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////
191)//IP:- Input1:- 5
// Output:- {2,3,5,7,11}
//take an integer(n) from user and return an array that contains the first n pri
me numbers.
//If n is negative print "Negative Number". If n is 0 print "No prime number fou
nd".
using System;
using System.Collections.Generic;
using System.Linq;
class Program
{
public static int[] FindPrime(int input1)
{
int[] result = { };
int count = 0;
List<int> li = new List<int>();
int[] r1 = { -1 };
int[] r2 = { -2 };
if (input1 > 0)
{
for (int i = 2; i < int.MaxValue; i++)
{
count = 0;
for (int j = 1; j <= i; j++)
{
if (i % j == 0)
{
count++;
}
}
if (count == 2)
{
li.Add(i);
}
if (li.Count == input1)
{
break;
}
}
}
else if (input1 == 0)
{
return r1;
}
else
{
return r2;
}
result = li.ToArray();
return result;

}
static void Main(string[] args)
{
Console.WriteLine("Enter a number");
int i1 = Convert.ToInt32(Console.ReadLine());
//int[] r1 = { -1 };
//int[] r2 = { -2 };
int[] result = FindPrime(i1);
if (i1 == 0)
{
Console.WriteLine("No prime number found");
}
else if (i1 < 0)
{
Console.WriteLine("Negative Number");
}
else
{
foreach (var item in result)
{
Console.WriteLine(item);
}
}
Console.ReadLine();
}
}

You might also like