C# Answers
C# Answers
BMI calculator
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace levelI01
{
class Program
{
static void Main(string[] args)
{
float input1, input2;
input1 = float.Parse(Console.ReadLine());
input2 = float.Parse(Console.ReadLine());
Console.WriteLine(UserProgramCode.BMICalc(input1, input2));
}
}
class UserProgramCode
{
public static string BMICalc(float input1, float input2)
{
float bmi;
}
}
Q2.Time Validation
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace levelI_02
{
class Program
{
static void Main(string[] args)
{
string str = Console.ReadLine();
if (ans == 1)
Console.WriteLine("Valid time format");
else if (ans == -1)
Console.WriteLine("Invalid time format");
}
}
class UserProgramCode
{
public static int validateTime(string str)
{
hr = int.Parse(str.Substring(0, 2));
min = int.Parse(str.Substring(3, 2));
string suf = str.Substring(5, 3);
if (hr > 12 || min > 60 || suf != " am" && suf != " pm")
return -1;
else
return 1;
}
}
}
Q3.IP Validator
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace level2
{
class Program
{
static void Main(string[] args)
{
string str = Console.ReadLine();
int no = UserProgramCode.ipValidator(str);
if(no==1)
Console.WriteLine("Valid");
else
Console.WriteLine("Invalid");
}
}
class UserProgramCode
{
flag++;
count = 0;
}
i++;
}
no = Int32.Parse(str.Substring(start, count));
flag++;
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace levelI04
{
class Program
{
static void Main(string[] args)
{
int n,i;
n = int.Parse(Console.ReadLine());
int[] arr = new int[n];
for (i = 0; i < n; i++)
arr[i] = int.Parse(Console.ReadLine());
int limit = int.Parse(Console.ReadLine());
int[] ans = UserProgramCode.GetElements(arr, limit);
if(ans[0]==-1)
Console.WriteLine("No element found");
else
{
foreach (int item in ans)
{
Console.WriteLine(item);
}
}
}
}
class UserProgramCode
{
public static int[] GetElements(int[] arr,int limit)
{
int n = arr.Length;
i=0;
for(j=0;j<n;j++)
{
if(arr[j]>limit)
{
temp[i]=arr[j];
i++;
}
}
if (temp[0] == 0)
{
temp[0] = -1;
return temp;
}
else
{
Console.WriteLine("");
Array.Sort(temp);
Array.Reverse(temp);
return temp;
}
}
}
Q5.Class Division
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace levelI05
{
class Program
{
static void Main(string[] args)
{
int sub1, sub2, sub3, sub4, sub5;
sub1 = int.Parse(Console.ReadLine());
sub2 = int.Parse(Console.ReadLine());
sub3 = int.Parse(Console.ReadLine());
sub4 = int.Parse(Console.ReadLine());
sub5 = int.Parse(Console.ReadLine());
string str="";
int avg=sum/5;
if(avg>=60)
str="First Class";
else if(avg>=50 && avg<=59)
str="Second Class";
else if(avg>=40 && avg<=49)
str="Third Class";
else if(avg<40)
str="Failed";
return str;
}
}
6)
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Reflection;
namespace ConsoleApplication2
{
class Program
{
static void Main(string[] args)
{
int n = int.Parse(Console.ReadLine());
if (n > 0)
{
int[] a = new int[n];
for(int i=0;i<n;i++)
{
a[i] = int.Parse(Console.ReadLine());
}
int sum = UserProgramCode.getSumOfPower(n, a);
Console.WriteLine(sum);
}
}
}
class UserProgramCode
{
public static int getSumOfPower(int size,int[] a)
{
int sum=0;
for(int i=0;i<size; i++)
{
sum+=(int)Math.Pow(a[i],i);
}
return sum;
}
}
7)
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Reflection;
namespace ConsoleApplication2
{
class Program
{
static void Main(string[] args)
{
int n = int.Parse(Console.ReadLine());
string[] str = new string[n];
if (n > 0)
{
for (int i = 0; i < n; i++)
{
str[i] = Console.ReadLine();
}
char c = char.Parse(Console.ReadLine());
int output = UserProgramCode.getCount(n, str, c);
if (output > 0)
{
Console.WriteLine(output);
}
else if (output == -1)
{
Console.WriteLine("No elements Found");
}
else if (output == -2)
{
Console.WriteLine("Only alphabets should be given");
}
}
}
}
class UserProgramCode
{
public static int getCount(int size,string[] str,char c)
{
int count=0;
char c_cap = c;
char c_small = c;
Regex reg = new Regex(@"^([A-Za-z]{1,})$");
foreach (string s in str)
{
if (!reg.IsMatch(s))
return -2;
string ch = c.ToString();
if (c >= 97 && c <= 122)
{
c_cap = (char)((int)(c) - 32);
}
else if (c >= 65 && c <= 90)
{
c_small = (char)((int)(c) + 32);
}
if (c_small == inp[0]||c_cap==inp[0])
count++;
}
if (count >= 1)
{
return count;
}
else
return -1;
}
}
8)
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Reflection;
namespace ConsoleApplication2
{
class Program
{
static void Main(string[] args)
{
string s = Console.ReadLine();
string output = UserProgramCode.negativeString(s);
Console.WriteLine(output);
}
}
}
class UserProgramCode
{
public static string negativeString(string str)
{
string neg_string = null;
string[] str1 = str.Split(' ');
StringBuilder sb = new StringBuilder();
for (int i=0;i<str1.Length;i++)
{
if (str1[i].Equals("is"))
{
sb.Append("is not ");
}
else
{
sb.Append(str1[i]+" ");
}
}
neg_string = sb.ToString();
return neg_string;
}
}
9)
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Reflection;
namespace ConsoleApplication2
{
class Program
{
static void Main(string[] args)
{
int n = int.Parse(Console.ReadLine());
int result=UserProgramCode.sumSquare(n);
if ( result== -1)
{
Console.WriteLine(-1);
}
else
{
Console.WriteLine(result);
}
}
}
class UserProgramCode
{
public static int sumSquare(int n)
{
int sum = 0;
if (n < 0)
return -1;
for (int i = 1; i <= n; i++)
{
sum += (int)Math.Pow(i, 2);
}
return sum;
}
}
10)
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Reflection;
namespace ConsoleApplication2
{
class Program
{
static void Main(string[] args)
{
int n = int.Parse(Console.ReadLine());
Console.WriteLine(UserProgramCode.calculateArea(n).ToString("#0.00"));
}
}
class UserProgramCode
{
public static double calculateArea(int n)
{
double area = 0;
area = Math.Round((3.14*n*n),2);
return area;
}
}
11.Reverse Substring
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication9
{
public class UserProgramCode
{
public static string reverseSubstring(string str, int start, int len)
{
StringBuilder sb = new StringBuilder();
string s = str.Substring(start, len);
char[] ch = s.ToCharArray();
Array.Reverse(ch);
foreach (char item in ch)
{
sb.Append(item);
}
return sb.ToString();
}
}
class Program
{
static void Main(string[] args)
{
string str=Console.ReadLine();
int start = int.Parse(Console.ReadLine());
int len = int.Parse(Console.ReadLine());
string str2 = UserProgramCode.reverseSubstring(str, start, len);
Console.WriteLine(str2);
Console.ReadLine();
}
}
}
-----------------------------------------------------------
12.Shipping Cost
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication9
{
public class UserProgramCode
{
public static double CalcShippingCost(int gms, char ch)
{
double temp;
if (ch == 'R')
{
if (gms <= 2000)
return gms * 0.25;
else
{
temp = 2000 * 0.25;
return temp + ((gms - 2000) * 0.35);
}
}
else if(ch=='X')
{
if (gms <= 2000)
return gms * 0.25 + 50;
else
{
temp = gms * 0.25;
return temp + ((gms - 2000) * 0.35) + 50;
}
}
else
return 0;
}
}
class Program
{
static void Main(string[] args)
{
int gms = int.Parse(Console.ReadLine());
char ch = char.Parse(Console.ReadLine());
Console.WriteLine(UserProgramCode.CalcShippingCost(gms, ch));
}
}
}
----------------------------------------------------------
13.Valid Negative Number
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication9
{
public class UserProgramCode
{
public static string validateNumber(string str)
{
str.ToCharArray();
int temp = 0;
if (str[0] == '-')
{
for (int i = 0; i < str.Length; i++)
if (str[i] >= 48 && str[i] <= 57)
temp = 1;
else
temp = 0;
if (temp == 1)
{
str = str.Substring(1, str.Length-1);
return str.ToString();
}
else
return "-1";
}
else
return "-1";
}
}
class Program
{
static void Main(string[] args)
{
string str = Console.ReadLine();
Console.WriteLine(UserProgramCode.validateNumber(str));
}
}
}
---------------------------------------------------------
14.Add non Common Elements
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication9
{
public class UserProgramCode
{
public static int sumNonCommonElement(int[] ar1,int n,int[] ar2,int m)
{
int a=0,b=0,c=0;
int sum=0;
int [] temp=new int[m+n];
//List<int> li=new List<int>;
if (a == 0 && b == 0)
{
for (int i = 0; i < n; i++)
for (int j = 0; j < m; j++)
if (ar1[i] == ar2[j])
{
ar1[i] = 0;
ar2[j] = 0;
}
return ar1.Sum()+ar2.Sum();
}
if (a == 1 && b == 0)
return -1;
else if (b == 1 && a == 0)
return -2;
if (a == 1 && b == 1)
return -3;
return 0;
}
}
class Program
{
static void Main(string[] args)
{
int n = int.Parse(Console.ReadLine());
int m = int.Parse(Console.ReadLine());
int[] ar1=new int[n];
int[] ar2=new int[m];
for(int i=0; i<n;i++)
ar1[i] = int.Parse(Console.ReadLine());
for (int i = 0; i < m; i++)
ar2[i] = int.Parse(Console.ReadLine());
int flag = UserProgramCode.sumNonCommonElement(ar1, n, ar2, m);
if(flag==-1)
Console.WriteLine("Input 1 has negative numbers");
else if(flag==-2)
Console.WriteLine("Input 2 has negative numbers");
else if(flag==-3)
Console.WriteLine("Both inputs has negative numbers");
else
Console.WriteLine(flag);
}
}
}
----------------------------------------------------------
15.Get the longest string
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
namespace mock_pgm2
{
public class Isletter
{
}
class Program
{
static void Main(string[] args)
{
Isletter obj=new Isletter();
char ch = char.Parse(Console.ReadLine());
if (alpha == 0)
{
Console.WriteLine("String contains non alphabetic characters.");
}
else
{
for (int i = 0; i < n; i++)
{
if (ls[i].ToCharArray()[0] == char.ToUpper(ch) ||
ls[i].ToCharArray()[0] == char.ToLower(ch))
{
if (ls[i].Length > count)
count = ls[i].Length;
temp = 1;
}
}
if (temp == 0)
Console.WriteLine("No elements found");
else
{
for (int i = 0; i < n; i++)
{
if (ls[i].Length == count)
Console.WriteLine(ls[i]);
}
}
}
}
}
}
16)
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Fwd_Prgs
{
public class UserProgramCode
{
public static string longestWordLength(string[] s)
{
int sum = 0;
for (int i = 0; i < s.Length; i++)
{
if (s[i].Length > sum)
{
sum = s[i].Length;
}
}
return sum.ToString();
}
class Program
{
static void Main(string[] args)
{
int n = int.Parse(Console.ReadLine());
string[] str=new string[n];
for (int i = 0; i < n; i++)
{
str[i] = Console.ReadLine();
}
string res = UserProgramCode.longestWordLength(str);
Console.WriteLine(res);
}
}
}
17)
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Fwd_Prgs
{
public class UserProgramCode
{
public static int GetAllElements(List<int> a, int n)
{
List<int> b=new List<int>();
int j = 0;
else
for(int i=0;i<b.Count;i++)
Console.WriteLine(b[i]);
return 0;
}
}
class Program
{
static void Main(string[] args)
{
int n= int.Parse(Console.ReadLine());
List<int> a = new List<int>();
for(int i=0;i<n;i++)
a.Add(int.Parse(Console.ReadLine()));
UserProgramCode.GetAllElements(a,n);
}
}
}
18)
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Fwd_Prgs
{
public class UserProgramCode
{
public static int getSumOfIntersection(int n1, int n2, int[] a, int[] b)
{
int sum=0;
for (int i = 0; i < n1; i++)
{
for (int j = 0; j < n2; j++)
if(a[i]==b[j])
sum = sum + a[i];
}
if (sum == 0)
return -1;
else
return sum;
}
}
class Program
{
static void Main(string[] args)
{
int n1 = int.Parse(Console.ReadLine());
int n2 = int.Parse(Console.ReadLine());
int[] a=new int[n1];
int[] b=new int[n2];
for(int i = 0; i < n1; i++)
a[i] = int.Parse(Console.ReadLine());
for(int i = 0; i <n2; i++)
b[i] = int.Parse(Console.ReadLine());
int res = UserProgramCode.getSumOfIntersection(n1, n2, a, b);
if(res==-1)
Console.WriteLine("No common elements found");
else
Console.WriteLine(res);
}
}
}
19)
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Fwd_Prgs
{
public class UserProgramCode
{
public static int findLargestDigit(int num)
{
if (num > 0)
{
int temp, res = 0;
class Program
{
static void Main(string[] args)
{
int n = int.Parse(Console.ReadLine());
int res = UserProgramCode.findLargestDigit(n);
if(res!=-1)
Console.WriteLine(res);
else
Console.WriteLine("The number should be a positive number");
}
}
}
20)
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Fwd_Prgs
{
public class UserProgramCode
{
public static string sumOfDigits(string str)
{
char[] s = str.ToCharArray();
int sum=0;
for (int i = 0; i < s.Length; i++)
if ((s[i] > 47) && (s[i] < 58))
{
sum = sum + (int)s[i]-48;
}
string res = sum.ToString();
if (sum == 0)
return "-1";
else
return res;
}
}
class Program
{
static void Main(string[] args)
{
string s = Console.ReadLine();
string res = UserProgramCode.sumOfDigits(s);
if(res=="-1")
Console.WriteLine("No digit present");
else
Console.WriteLine(res);
}
}
}
qn..21
class Program
{
static void Main(string[] args)
{
string str = Console.ReadLine();
string s1=UserProgramCode.method1(str);
Console.WriteLine(s1);
Console.ReadLine();
}
}
class UserProgramCode
{
public static string method1(string s)
{
int i = 0, a = 0;
StringBuilder sb = new StringBuilder();
for (i = 0; i < s.Length; i++)
{
if (i % 2 == 0)
{
if (s[i] == 'z')
sb.Append('a');
else
{
a = Convert.ToInt16(s[i]);
Console.WriteLine(a);
a = a + 1;
sb.Append(Convert.ToChar(a));
}
}
else
sb.Append(s[i]);
}
return sb.ToString();
}
}
qn..22
class Program
{
static void Main(string[] args)
{
int a = int.Parse(Console.ReadLine());
int b = int.Parse(Console.ReadLine());
int c = int.Parse(Console.ReadLine());
int s1 = UserProgramCode.arithmeticOperation(a,b,c);
if (s1 == -1)
Console.WriteLine("Invalid Operator");
else if (s1 == -2)
Console.WriteLine("Invalid Operands");
else
Console.WriteLine(s1);
Console.ReadLine();
}
}
class UserProgramCode
{
public static int arithmeticOperation(int a,int b,int c)
{
if (a > 0 && a < 5)
{
if (b < 0 || c < 0)
return -2;
else
if (a == 1)
return b + c;
else if (a == 2)
return b - c;
else if (a == 3)
return b * c;
else
return b / c;
}
else
return -1;
}
}
qn..23
class Program
{
static void Main(string[] args)
{
string str=Console.ReadLine();
string s1 = UserProgramCode.getMiddleChars(str);
Console.WriteLine(s1);
Console.ReadLine();
}
}
class UserProgramCode
{
public static string getMiddleChars(string s)
{
int i = 0;
StringBuilder sb = new StringBuilder();
if (s.Length % 2 == 0)
{
i = s.Length / 2;
sb.Append(s[i - 1]);
sb.Append(s[i]);
}
return sb.ToString();
}
}
qn..24
class Program
{
static void Main(string[] args)
{
string s=Console.ReadLine();
int i=Convert.ToInt16(Console.ReadLine());
string s1 = UserProgramCode.addDays(s,i);
if (s1 == "-1")
Console.WriteLine("n value is negative");
else if (s1 == "-2")
Console.WriteLine("Invalid date format");
Console.WriteLine(s1);
Console.ReadLine();
}
}
class UserProgramCode
{
public static string addDays(string s,int a)
{
string format = "MM/dd/yyyy";
DateTime dt;
bool
b=DateTime.TryParseExact(s,format,null,System.Globalization.DateTimeStyles.None,out
dt);
if (!b)
return "-2";
if (a < 0)
return "-1";
dt=dt.AddDays(a);
return dt.ToString("MM/dd/yyyy");
}
}
qn..25
class Program
{
static void Main(string[] args)
{
int i=Convert.ToInt32(Console.ReadLine());
int s1 = UserProgramCode.sumOfSquareofEvenDigits(i);
Console.WriteLine(s1);
Console.ReadLine();
}
}
class UserProgramCode
{
public static int sumOfSquareofEvenDigits(int a)
{
int sum=0;
string a1 = a.ToString();
int a2 = 0;
for (int i = 0; i < a1.Length; i++)
{
a2 = (int)(a1[i])-48;
if (a2 % 2 == 0)
{
}
}
return sum;
}
}
qn..26
class Program
{
static void Main(string[] args)
{
string str = Console.ReadLine();
int i = UserProgramCode.validateColorCode(str);
if (i == 1)
Console.WriteLine("Valid");
else
Console.WriteLine("Invalid");
Console.ReadLine();
}
}
class UserProgramCode
{
public static int validateColorCode(string s)
{
int flag = 0;
if(s.StartsWith("#"))
{
if (s.Length == 7)
{
char[] ch = s.ToCharArray();
for(int i=1;i<=6;i++)
{
if (char.IsDigit(ch[i]) || "ABCDEF".Contains(ch[i]))
{
flag = 1;
}
else
{
flag = 0;
break;
}
}
}
}
if (flag == 0)
return -1;
else
return 1;
}
}
qn..27
class Program
{
static void Main(string[] args)
{
int n = Convert.ToInt16(Console.ReadLine());
int i = UserProgramCode.getSumOfNfibos(n);
Console.WriteLine(i);
Console.ReadLine();
}
}
class UserProgramCode
{
public static int getSumOfNfibos(int n)
{
int f = 0, f1 = -1, f2 = 1, sum = 0;
for (int i = 0; i < n; i++)
{
f = f1 + f2;
f1 = f2;
f2 = f;
sum = sum + f;
}
return sum;
}
}
qn..28
class Program
{
static void Main(string[] args)
{
int i = 0;
int n = int.Parse(Console.ReadLine());
string[] s = new string[50];
for (i = 0; i < n; i++)
s[i] = Console.ReadLine();
s[i] = "\0";
int sl = UserProgramCode.shortestWordLength(s);
Console.WriteLine(sl);
Console.ReadLine();
}
}
class UserProgramCode
{
public static int shortestWordLength(string[] s)
{
int sl =s[0].Length;
for (int i = 1; s[i]!="\0"; i++)
{
if (s[i].Length < sl)
sl = s[i].Length;
}
return sl;
}
}
qn..29
class Program
{
static void Main(string[] args)
{
string s1 = Console.ReadLine();
string s2 = Console.ReadLine();
int n = int.Parse(Console.ReadLine());
int sl = UserProgramCode.calculateBill(s1,s2,n);
Console.WriteLine(sl);
Console.ReadLine();
}
}
class UserProgramCode
{
public static int calculateBill(string s1,string s2,int n)
{
int sum = 0;
string ss1 = s1.Substring(5);
string ss2 = s2.Substring(5);
int a = int.Parse(ss1);
int b = int.Parse(ss2);
sum = (b - a) * n;
return sum;
}
}
qn..30
class Program
{
static void Main(string[] args)
{
int n = int.Parse(Console.ReadLine());
int sl = UserProgramCode.sumOfCube(n);
if(s1==-1)
console.writeline("The input is not a natural number");
else
Console.WriteLine(sl);
Console.ReadLine();
}
}
class UserProgramCode
{
public static int sumOfCube(int n)
{
if(n<0)
return -1;
int sum = 0;
for (int i = 1; i <= n; i++)
sum = sum + (i * i * i);
return sum;
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Workout41
{
class UserProgramCode
{
public static string formNewWord(string s,int n)
{
string s1,s2;
int l,n1;
l = s.Length;
if (l > n * 2)
{
n1 = l - n;
s1 = s.Substring(0, n) + s.Substring(n1, n);
return s1;
}
else
{
return "";
}
}
}
class Program
{
static void Main(string[] args)
{
string s;
int n;
UserProgramCode u = new UserProgramCode();
s = Console.ReadLine();
n = int.Parse(Console.ReadLine());
s = UserProgramCode.formNewWord(s,n);
Console.WriteLine(s);
}
}
}
===================================================================
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace program32
{
class Program
{
static void Main(string[] args)
{
int n;
n=UserProgramCode.checkcharacters("the picture was great");
Console.WriteLine(n);
}
}
class UserProgramCode
{
public static int checkcharacters(string str)
{
int len = str.Length;
string str1 = str.Substring(0, 1);
string str2 = str.Substring(len-1);
if (str1.Equals(str2))
{
return 1;
}
else
{
return -1;
}
}
}
}
===================================================================
33.count characters
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace program33
{
class Program
{
static void Main(string[] args)
{
int n;
n= UserProgramCode.countcharacters("qwerty");
Console.WriteLine(n);
}
}
class UserProgramCode
{
public static int countcharacters(string str)
{
int len = str.Length;
return len;
}
}
}
===================================================================
34.validate id location
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
namespace prgrm35
{
class Program
{
static void Main(string[] args)
{
int i;
i = UserProgramCode.validateIDlocations("CTS-HYD-2000", "HYDERABAD");
if (i == 1)
{
Console.WriteLine("valid");
}
else
{
Console.WriteLine("Invalid");
}
}
}
class UserProgramCode
{
public static int validateIDlocations(string s1, string s2)
{
int output = 0;
Regex reg = new Regex(@"^([CTS]+[-]+([A-Za-z]{3})+[-]+([0-9]{4}))$");
if(reg.IsMatch(s1))
{
string res=s2.ToUpper();
if (s1.Contains(res.Substring(0, 3)))
{
output = 1;
}
else
{
output = -1;
}
}
else
{
output = -2;
}
return output;
===================================================================
35.string manipulation
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace prgm34
{
class Program
{
static void Main(string[] args)
{
string ans;
ans= UserProgramCode.stringmanipulation("sathish", "kumar");
Console.WriteLine(ans);
}
}
class UserProgramCode
{
public static string stringmanipulation(string str1, string str2)
{
string res1, res2, res3, rev = "";
int len, len2, len3;
len = str1.Length;
if (len % 2 == 0)
{
len2 = len / 2;
res3=str1.Substring(len2);
}
else
{
len2 = (len / 2) + 1;
res3 = str1.Substring(len2);
}
len3 = str2.Length-1;
while (len3 >= 0)
{
rev = rev + str2[len3];
len3--;
}
res1 = str1.Substring(0, len2);
res2 = res1 + rev + res3;
return res2;
}
}
===================================================================
question 36
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace question36
{
class Program
{
static void Main(string[] args)
{
int n, c;
n = Convert.ToInt32(Console.ReadLine());
c = UserProgramCode.checkSum(n);
if (c == 1)
Console.WriteLine("Odd");
else Console.WriteLine("Even");
}
}
class UserProgramCode
{
public static int checkSum(int a)
{
int rem, sum = 0;
while (a > 0)
{
rem = a % 10;
if (rem % 2 == 1)
{ sum = sum + rem; }
a = a / 10;
}
if (sum % 2 == 1)
return (1);
else return (-1);
============================================================
question 37 :
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace question36
{
class Program
{
static void Main(string[] args)
{
int n, c,m;
n = Convert.ToInt32(Console.ReadLine());
m = Convert.ToInt32(Console.ReadLine());
c = UserProgramCode.findGiftVoucher(n,m);
Console.WriteLine(c);
}
}
class UserProgramCode
{
public static int findGiftVoucher(int a,int b)
{
if(a>0 && b>0 && a<7 && b<7)
{
if ((a + b == 2) || (a + b == 3) || (a + b == 6) || (a + b == 11))
return (1000);
else if ((a + b == 4) || (a + b == 7) || (a + b == 10))
return (3000);
else if ((a + b == 5) || (a + b == 8) || (a + b == 9) || (a + b ==
12))
return (5000);
}
else return(-1);
return 0;
}
}
============================================================
question 38 :
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace q38
{
class Program
{
static void Main(string[] args)
{
int n=int.Parse(Console.ReadLine());
List<string> list=new List<string>(n);
int i;
for (i = 0; i < n; i++)
list.Add(Console.ReadLine());
char c = char.Parse(Console.ReadLine());
Console.WriteLine(GetshortestString(list, c));
}
static string GetshortestString(List<string> list, char c)
{
string min = "";
int len = 99;
int i;
for (i = 0; i < list.Count; i++)
{
if (list[i][0].CompareTo(c) == 0)
{
============================================================
question 39 :
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace question36
{
class Program
{
static void Main(string[] args)
{
int n, c=0;
n = Convert.ToInt32(Console.ReadLine());
if (n > 0)
{
c = UserProgramCode.reverseNumber(n);
}
Console.WriteLine(c);
}
}
class UserProgramCode
{
public static int reverseNumber(int a)
{
int rem, sum = 0;
while (a > 0)
{
rem = a % 10;
return (sum);
============================================================
program : 40
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace prog40
{
class Program
{
static void Main(string[] args)
{
string str, str1, str2;
str = Console.ReadLine();
str1=Console.ReadLine();
str2 = Console.ReadLine();
if(stringFinder(str,str1,str2)==1)
Console.WriteLine("Yes");
else
Console.WriteLine("No");
}
static int stringFinder(string str,string str1,string str2)
{
int str1_len = str1.Length;
int str2_len = str2.Length;
string temp="";
int st=0,count1=0,count2=0;
while (temp != str1)
{
temp = str.Substring(st, str1_len);
st++;
}
if (temp == str1)
{
count1++;
}
// Console.WriteLine(temp + "\t" + st);
string sub = str.Substring((st + str1_len - 1));
temp = "";
st = 0;
while (temp != str2)
{
temp = str.Substring(st, str2_len);
st++;
}
if (temp == str2)
{
count2++;
}
if(count1==1 && count2==1)
return 1;
else
return 2;
// Console.WriteLine(temp+"\t"+st);
}
}
}
============================================================
41.Form New Word:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Workout41
{
class UserProgramCode
{
public static string formNewWord(string s,int n)
{
string s1,s2;
int l,n1;
l = s.Length;
if (l > n * 2)
{
n1 = l - n;
s1 = s.Substring(0, n) + s.Substring(n1, n);
return s1;
}
else
{
return "";
}
}
}
class Program
{
static void Main(string[] args)
{
string s;
int n;
UserProgramCode u = new UserProgramCode();
s = Console.ReadLine();
n = int.Parse(Console.ReadLine());
s = UserProgramCode.formNewWord(s,n);
Console.WriteLine(s);
}
}
}
===============================================================-
42.Check Characters
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Workout42
{
class UserProgramCode
{
public static int checkCharacters(string s)
{
string sl;
sl=s.Substring(0,1);
sl = sl.ToLower();
if (s.EndsWith(sl))
return 1;
else
return 0;
}
}
class Program
{
static void Main(string[] args)
{
string s;
int i;
//UserProgramCode u = new UserProgramCode();
s = Console.ReadLine();
s = s.ToLower();
i = UserProgramCode.checkCharacters(s);
if (i==1)
Console.WriteLine("The characters are same");
else
Console.WriteLine("The characters are different");
}
}
}
===============================================================-
43. CountCharacters
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Workout43
{
class UserProgramCode
{
public static int countCharacters(string s)
{
int l;
l = s.Length;
return l;
}
}
class Program
{
static void Main(string[] args)
{
//UserProgramCode u = new UserProgramCode();
string s;
int n;
s = Console.ReadLine();
n = UserProgramCode.countCharacters(s);
Console.WriteLine(n);
}
}
}
===============================================================-
44. Find total number of days in given month
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Workout44
{
class UserProgramCode
{
public static int getNumberOfDays(int y,int m)
{
int d;
d = System.DateTime.DaysInMonth(y,m+1);
return d;
}
}
class Program
{
static void Main(string[] args)
{
//UserProgramCode u = new UserProgramCode();
int y,m,n;
y = int.Parse(Console.ReadLine());
m= int.Parse(Console.ReadLine());
n = UserProgramCode.getNumberOfDays(y,m);
Console.WriteLine(n);
}
}
}
===============================================================-
45. Find Lowest
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Workout45
{
class UserProgramCode
{
public static int findLowest(int[] a)
{
int i, j, t, n;
n = a.Length;
t = a[0];
for (i = 0; i < n; i++)
{
for (j = i + 1; j < n+1; j++)
{
if (a[i] < 0)
{
t = -1;
return t;
}
else if (t > a[i])
{
t = a[i];
a[i] = a[j];
a[j] = t;
}
}
}
return t;
}
}
class Program
{
static void Main(string[] args)
{
//UserProgramCode u = new UserProgramCode();
int i,n,s;
n = int.Parse(Console.ReadLine());
int[] a = new int[n];
for (i = 0; i < n;i++ )
a[i] = int.Parse(Console.ReadLine());
s = UserProgramCode.findLowest(a);
if(s>=0)
Console.WriteLine(s);
else if (s < 0)
Console.WriteLine("Negative Numbers present");
else { }
}
}
}
===============================================================-
46.find average:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication18
{
class UserProgramCode
{
public static float compute(int[] array, int size)
{
float avg,sum = 0;
int i;
foreach (int a in array)
{
if (a < 0)
return -1;
}
for (i = 0; i < size; i++)
{
sum = sum + array[i];
}
avg = sum / size;
return avg;
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication18
{
class Program
{
static void Main(string[] args)
{
UserProgramCode u = new UserProgramCode();
int n;
float avg;
n = int.Parse(Console.ReadLine());
int[] a = new int[n];
for (int i = 0; i < n; i++)
{
a[i] = int.Parse(Console.ReadLine());
}
avg = UserProgramCode.compute(a, n);
if (avg == -1)
{
Console.WriteLine("Negative numbers present");
}
else
Console.WriteLine(String.Format("{0:0.0}",avg));
}
}
}
====================================-
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication18
{
class UserProgramCode
{
public static int validatephonenumber(string s)
{
int len = s.Length;
int digit = 0, flag = 0;
char[] a = s.ToCharArray();
for (int i = 0; i < len; i++)
{
if ((a[i] == '-') || char.IsDigit(a[i]))
flag++;
}
if (flag == len)
{
}
if (digit == 10)
return 1;
else
return 2;
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication18
{
class Program
{
static void Main(string[] args)
{
UserProgramCode u = new UserProgramCode();
string s;
int result;
s = Console.ReadLine();
result = UserProgramCode.validatephonenumber(s);
if(result==1)
Console.WriteLine("valid");
else if(result==2)
Console.WriteLine("Invalid");
}
}
}
=========================================================
48.check supply
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication18
{
class UserProgramCode
{
public static string checksupply(int n1, int n2,bool value)
{
if (value == true && n1 == 0)
{
return ("OutOfStock");
}
else
else
if (value == false)
{
return "Cannot Supply";
}
else
return "";
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication18
{
class Program
{
static void Main(string[] args)
{
UserProgramCode u = new UserProgramCode();
int n1, n2;
bool value;
string output;
n1 = int.Parse(Console.ReadLine());
n2=int.Parse(Console.ReadLine());
value=bool.Parse(Console.ReadLine());
output = UserProgramCode.checksupply(n1, n2, value);
Console.WriteLine(output);
}
}
===========================
49.count characters
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication18
{
class UserProgramCode
{
public static int countcharachters(string[] s)
{
int sum = 0,flag = 0 ;
foreach (string s1 in s)
{
char[] ch = s1.ToCharArray();
foreach (char c in ch)
{
if (char.IsLetter(c))
{
flag++;
}
}
}
foreach (string s1 in s)
{
sum = sum + s1.Length;
}
if(flag==sum)
return sum;
else
return -1;
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication18
{
class Program
{
static void Main(string[] args)
{
UserProgramCode u=new UserProgramCode();
int n = int.Parse(Console.ReadLine());
string[] s=new string[n];
int result;
for (int i = 0; i < n; i++)
s[i] = Console.ReadLine();
result=UserProgramCode.countcharachters(s);
if(result==-1)
Console.WriteLine("Invalid Input");
else
Console.WriteLine(result);
}
}
}
}
=============================================
50.Get Big Diff
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication18
{
class Program
{
static void Main(string[] args)
{
UserProgramCode u=new UserProgramCode();
int n = int.Parse(Console.ReadLine());
int[] a = new int[n];
int result;
for (int i = 0; i < n; i++)
a[i] = int.Parse(Console.ReadLine());
result = UserProgramCode.getBigDiff(a);
Console.WriteLine(result);
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication18
{
class UserProgramCode
{
public static int getBigDiff(int[] a)
{
int min = a[0],max=a[0],diff=0;
for (int i = 0; i < a.Length; i++)
{
if (a[i] >= max)
max = a[i];
if (a[i] <= min)
min = a[i];
}
diff= max - min;
return diff;
}
}
}
=======================================
Program 51:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace progm51
{
class Program
{
static void Main(string[] args)
{
decimal inp=Convert.ToDecimal(Console.ReadLine());
string outp=UserProgramCode.EfficiencyChecker(inp);
Console.WriteLine(outp);
}
}
class UserProgramCode
{
public static string EfficiencyChecker(decimal a)
{
if ((a >= 1) && (a <= 3))
{
return "Highly efficient";
}
else if ((a > 3) && (a <= 4))
{
return "Improve speed";
}
else if ((a > 4) && (a <= 5))
{
return "Need Training";
}
else if (a > 5)
{
return "Leave the company";
}
else
{
return "Invalid Input";
}
}
}
}
===========================================================================
Program 52:
============
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace progm52
{
class Program
{
static void Main(string[] args)
{
string inpt;
inpt = Convert.ToString(Console.ReadLine());
string outp=UserProgramCode.removeEvenVowels(inpt);
Console.WriteLine(outp);
}
}
class UserProgramCode
{
public static string removeEvenVowels(string a)
{
int maxi=a.Length;
}
========================================================================
Program 53:
=========--
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace progm53
{
class Program
{
static void Main(string[] args)
{
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 l = Convert.ToInt32(Console.ReadLine());
int h = Convert.ToInt32(Console.ReadLine());
int output=UserProgramCode.countBetweenNumbers(a, l, h);
if (output != -1)
{
Console.WriteLine(output);
}
else
{
Console.WriteLine("Negative value Present");
}
}
}
class UserProgramCode
{
public static int countBetweenNumbers(int[] inp,int x,int y)
{
int max1=inp.Length;
int count = 0;
for (int i = 0; i < max1; i++)
{
if ((inp[i] < 0) || (x < 0) || (y < 0))
{
count= -1;
}
else
{
if ((inp[i] >= x) && (inp[i] <= y))
{
count++;
}
}
}
return count;
}
}
}
=====================================================================
Program 54:
=========--
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace progm54
{
class Program
{
static void Main(string[] args)
{
string inp1 = Console.ReadLine();
string inp2 = Console.ReadLine();
string output = UserProgramCode.concatstring(inp1, inp2);
Console.WriteLine(output);
}
}
class UserProgramCode
{
public static string concatstring(string inputstr1, string inputstr2)
{
int x = inputstr1.Length;
int y = inputstr2.Length;
string ans;
if (x == y)
{
ans = inputstr1 + inputstr2;
}
else if (x > y)
{
int z = x - y;
string inputstring1 = inputstr1.Remove(0, z);
ans = inputstring1 + inputstr2;
}
else
{
int z = y - x;
string inputstring2 = inputstr1.Remove(0, z);
ans = inputstr1 + inputstring2;
}
return ans;
}
}
=====================================================================
Program 55:
============
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace progm55
{
class UserProgramCode
{
public static int[] sortList(int[] a)
{
int temp;
if (maxi == 0)
{
a[0] = -1;
}
else
{
if (a[i] < 0)
{
a[0] = -1;
else
{
if (a[i] < a[j])
{
temp = a[i];
a[i] = a[j];
a[j] = temp;
}
}
}
return a;
}
}
class Program
{
static void Main(string[] args)
{
int n = Convert.ToInt32(Console.ReadLine());
int[] a=new int[n];
int[] output=new int[n];
for (int i = 0; i < n; i++)
{
a[i] = Convert.ToInt32(Console.ReadLine());
}
output=UserProgramCode.sortList(a);
if (output[0] != -1)
{
for (int i = 0; i < n; i++)
{
Console.WriteLine(output[i]);
}
}
else
{
Console.WriteLine("Invalid Input");
}
}
}
===========================================================
PROGRAM 56.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace level1_56
{
class Program
{
static void Main(string[] args)
{
string str1;
int x;
str1 = Console.ReadLine();
x=UserProgramCode.validatePassword(str1);
if(x==1)
Console.WriteLine("valid input");
else
Console.WriteLine("Invalid input");
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace level1_56
{
class UserProgramCode
{
public static int validatePassword(string str)
{
bool a, b, c;
a = str.Contains("@");
b = str.Contains("#");
c = str.Contains("$");
if (a && b && c)
{
if ((str.Length >= 6) && (str.Length <= 20))
{
return 1;
}
}
return -1;
}
}
}
===========================================================
PROGRAM 57.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace level1_57
{
class Program
{
static void Main(string[] args)
{
string s = Console.ReadLine();
string c;
c=UserProgramCode.getLargestWord(s);
Console.WriteLine(c);
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace level1_57
{
class UserProgramCode
{
public static string getLargestWord(string str)
{
int l=0,max=0,ind=-1;
string[] s=new string[100];
s = str.Split(' ');
for (int i = 0; i < s.Length; i++)
{
l = s[i].Length;
if (max < l)
{
max = l;
ind = i;
}
}
return s[ind];
}
}
}
===========================================================
PROGRAM 58.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace level1_58
{
class Program
{
static void Main(string[] args)
{
int k;
string intime, outtime;
intime = Console.ReadLine();
outtime = Console.ReadLine();
k = UserProgramCode.getMonthDifference(intime, outtime);
if (k == -1)
{
Console.WriteLine("Invalid format");
}
else
Console.WriteLine(k);
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace level1_58
{
class UserProgramCode
{
public static int getMonthDifference(string intime, string outtime)
{
string s;
s = "yyyy-MM-dd";
DateTime i, o;
bool k = DateTime.TryParseExact(intime, s, null,
System.Globalization.DateTimeStyles.None, out i);
if (k == false)
return -1;
bool j = DateTime.TryParseExact(outtime, s, null,
System.Globalization.DateTimeStyles.None, out o);
if (j == false)
return -1;
int a1 = i.Month;
int a2 = o.Month;
int d;
if (a1 > a2)
d = a1 - a2;
else
d = a2 - a1;
return d;
}
}
}
===========================================================
PROGRAM 59.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace level1_59
{
class Program
{
static void Main(string[] args)
{
int n,x;
n = Convert.ToInt32(Console.ReadLine());
x = UserProgramCode.addSeries(n);
Console.WriteLine(x);
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace level1_59
{
class UserProgramCode
{
public static int addSeries(int a)
{
int t = 0, k = 1;
for (int i = 0; k <= a; i++)
{
if (i == 0)
{
t = t + k;
}
else if (i == 1)
{
t = t + k;
}
else if (i % 2 != 0)
{
t = t + k;
}
else
{
t = t - k;
}
k = k + 2;
}
return t;
}
}
}
===========================================================
PROGRAM 60.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace level1_60
{
class Program
{
static void Main(string[] args)
{
int x;
string s = Console.ReadLine();
x = UserProgramCode.validatestrings(s);
if (x == 1)
{
Console.WriteLine("valid");
}
else
{
Console.WriteLine("Invalid");
}
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
namespace level1_60
{
class UserProgramCode
{
public static int validatestrings(string str)
{
int output1 = 0;
Regex reg = new Regex(@"^([C]+[T]+[S]+[-]+([0-9]{3}))$");
if (reg.IsMatch(str))
{
output1 = 1;
}
else
{
output1 = -1;
}
return output1;
}
}
}
===========================================================
61.
class Program
{
static void Main(string[] args)
{
string s;
s = Console.ReadLine();
userprogramcode obj = new userprogramcode();
Console.WriteLine(obj.fileIdentifier(s));
}
}
public class userprogramcode
{
public string fileIdentifier(string s)
{
string[] str;
str=s.Split('.');
return str[1];
}
}
========================================================================
62
class Program
{
static void Main(string[] args)
{
int f = 0;
string s;
s = Console.ReadLine();
userprogramcode obj = new userprogramcode();
f=obj.validatenumber(s);
if(f==1)
Console.WriteLine("Valid number format");
if(f==-1)
Console.WriteLine("Invalid number format");
}
}
public class userprogramcode
{
public int validatenumber(string s)
{
if (Regex.IsMatch(s, @"^\d{3}[-]\d{3}[-]\d{4}$"))
{
return 1;
}
else
return -1;
}
}
=====================================================================
63
class Program
{
static void Main(string[] args)
{
int n;
n = Convert.ToInt32(Console.ReadLine());
int[] a=new int[n];
for (int i = 0; i < n; i++)
{
a[i] = Convert.ToInt32(Console.ReadLine());
}
}
}
public class userprogramcode
{
public int addEvenOdd(int[] a)
{
int sum=0;
foreach (var n in a)
{
if (n % 2 == 0)
sum += Convert.ToInt32(Math.Pow(n, 2));
else
sum += Convert.ToInt32(Math.Pow(n, 3));
}
return sum;
}
}
===================================================================================
64
class Program
{
static void Main(string[] args)
{
string s;
s = Console.ReadLine();
}
}
public class userprogramcode
{
public string nameFormatter(string s)
{
string[] str;
str = s.Split(' ');
s = str[1] + ", " + str[0][0];
return s;
}
}
===================================================================================
=
65
class Program
{
static void Main(string[] args)
{
string s,s1;
s = Console.ReadLine();
s1 = Console.ReadLine();
userprogramcode obj = new userprogramcode();
Console.WriteLine(obj.getDateDifference(s,s1));
}
}
public class userprogramcode
{
public string getDateDifference(string s,string s1)
{
string fm="yyyy-MM-dd";
DateTime dt1,dt;
DateTime.TryParseExact(s,fm,null,System.Globalization.DateTimeStyles.None,out dt);
DateTime.TryParseExact(s1, fm, null,
System.Globalization.DateTimeStyles.None, out dt1);
return Convert.ToString((dt1-dt).Days);
}
}
=================================================================
66)using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication24
{
class Program
{
static void Main(string[] args)
{
string s = Console.ReadLine();
int a = UserProgramCode.countSequentialChars(s);
if(a==-1)
Console.WriteLine("No Repeated Words Found");
else
Console.WriteLine(a);
Console.ReadLine();
}
}
class UserProgramCode
{
public static int countSequentialChars(string s)
{
int l = s.Length;
string[] st = new string[50];
int count = 0;
int c=0;
if (st[k] == st[k+1])
count++;
else
count = 0;
if (count == 2)
c++;
}
if(c==0)
return -1;
else
return c;
}
}
}
==============================================================
67)using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication24
{
class Program
{
static void Main(string[] args)
{
int n=Convert.ToInt32(Console.ReadLine());
int[] s =new int[n];
for(int i=0;i<n;i++)
s[i] =Convert.ToInt32(Console.ReadLine()) ;
double a = UserProgramCode.getBoundaryAverage(s);
Console.WriteLine(a);
Console.ReadLine();
}
}
class UserProgramCode
{
public static double getBoundaryAverage(int[] a)
{
double d,e;
d=((a.Max()+a.Min())/2.0);
e = Math.Round(d, 1);
return e;
}
}
}
==============================================================
68)
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
string s = Console.ReadLine();
string a = UserProgramCode.reverseString(s);
if (a == "-1")
Console.WriteLine("Invalid Input");
else
Console.WriteLine(a);
Console.ReadLine();
}
}
class UserProgramCode
{
public static string reverseString(string a)
{
int l=a.Length;
Array.Reverse(c);
sb.Append(c);
sb.Append(" ");
}
return sb.ToString();
}
}
}
==============================================================
69)using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
string s = Console.ReadLine();
char c = Convert.ToChar(Console.ReadLine());
int a = UserProgramCode.findOccurence(s,c);
if (a == -1)
Console.WriteLine("Invalid Input");
else
Console.WriteLine(a);
Console.ReadLine();
}
}
class UserProgramCode
{
public static int findOccurence(string a,char b)
{
int count = 0;
foreach (char e in a)
{
if (e==char.ToUpper(b)||e==char.ToLower(b))
count++;
}
return count;
}
}
}
==============================================================
namespace ConsoleApplication26
{
class Program
{
static void Main(string[] args)
{
float s = float.Parse((Console.ReadLine()));
int a = UserProgramCode.calculateCommission(s);
if (a == -1)
Console.WriteLine("Invalid Input");
else
Console.WriteLine(a);
Console.ReadLine();
}
}
class UserProgramCode
{
public static int calculateCommission(float a)
{
double com;
double r = Convert.ToDouble(a);
if (r < 0)
{
return -1;
}
else if (r < 10000)
{
return 0;
}
else if (r >= 10000 && r <= 25000)
{
com = r * 1.0 / 10.0;
return Convert.ToInt32(com);
}
return -1;
}
}
}
==============================================================
Program 71:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
namespace ConsoleApplication18
{
class Program
{
static void Main(string[] args)
{
int n = Convert.ToInt32(Console.ReadLine());
string[] a = new string[n];
string[] b;
for (int i = 0; i < a.Length; i++)
a[i] = Console.ReadLine();
b = userProgramCode.sortArrayElement(a);
foreach(string c in b)
Console.WriteLine(c);
Console.ReadLine();
}
}
class userProgramCode
{
public static string[] sortArrayElement(string[] a)
{
string[] b=new string[1];
for (int i = 0; i < a.Length; i++)
{
for (int j = 0; j < a[i].Length; j++)
{
if (!char.IsLetterOrDigit(a[i][j]))
{
b[0] = "-1";
return b;
}
}
}
Array.Sort(a, StringComparer.Ordinal);
return a;
}
}
}
====================================================================
Program 72:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
namespace ConsoleApplication18
{
class Program
{
static void Main(string[] args)
{
int n = Convert.ToInt32(Console.ReadLine());
string[] a = new string[n];
for (int i = 0; i < a.Length; i++)
a[i] = Console.ReadLine();
int r = userProgramCode.shortestWordLength(a);
Console.WriteLine(r);
Console.ReadLine();
}
}
class userProgramCode
{
public static int shortestWordLength(string[] a)
{
int min=1000;
for (int i = 0; i < a.Length; i++)
{
if (i == 0)
min = a[i].Length;
else
{
if (min > a[i].Length)
min = a[i].Length;
}
}
return min;
}
}
}
====================================================================
Program 73:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
namespace ConsoleApplication18
{
class Program
{
static void Main(string[] args)
{
float f=float.Parse(Console.ReadLine());
char c=Convert.ToChar(Console.ReadLine());
float p=userProgramCode.CalcShippingCost(f,c);
Console.WriteLine(p.ToString("F"));
Console.ReadLine();
}
}
class userProgramCode
{
public static float CalcShippingCost(float i, char c)
{
float p;
if (c == 'X')
i += 50;
if (i > 2000)
{
float d = i - 2000;
p =Convert.ToSingle(2000 * 0.25);
p +=Convert.ToSingle( (d * 0.35));
}
else
p = Convert.ToSingle(i * 0.25);
return p;
}
}
}
====================================================================
Program 74:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
namespace ConsoleApplication18
{
class Program
{
static void Main(string[] args)
{
int n = Convert.ToInt32(Console.ReadLine());
string r = userProgramCode.checkStrongNumber(n);
Console.WriteLine(r);
Console.ReadLine();
}
}
class userProgramCode
{
public static String checkStrongNumber(int i)
{
if (i < 0)
return "Invalid Input";
int t, r, f = 0;
t = i;
while (t > 0)
{
int fact = 1;
r = t % 10;
for (int j = 1; j <= r; j++)
{
fact *= j;
}
f += fact;
t /= 10;
}
if (f == i)
return f + " is a Strong Number";
else
return "Sum of all digits factorial is " + f;
}
}
}
Program 75:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
namespace ConsoleApplication18
{
class Program
{
static void Main(string[] args)
{
string s=Console.ReadLine();
int i=userProgramCode.getdigits(s);
Console.WriteLine(i);
Console.ReadLine();
}
}
class userProgramCode
{
public static int getdigits(string i)
{
int s=0;
for (int j = 0; j < i.Length; j++)
{
if ((char.IsLetterOrDigit(i[j])))
{
if (char.IsDigit(i[j]))
s += (Convert.ToInt32(i[j])-48);
}
else
return -1;
}
if (s == 0)
return -2;
else
return s;
}
}
}
====================================================================
76.
//program.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;
namespace trial
{
class Program
{
static void Main(string[] args)
{
String str = Console.ReadLine();
String res = UserProgramCode.getSpecialChar(str);
Console.WriteLine(res);
}
}
}
//UserProgramCode.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace trial
{
class UserProgramCode
{
public static string getSpecialChar(string input1)
{
int num = 0;
StringBuilder sb=new StringBuilder();
int sp = 0;
int len = input1.Length;
for (int i = 0; i < len; i++)
{
char c = input1[i];
if (char.IsDigit(c))
{
num++;
sb.Append(c);
}
if (c == '#' || c == '$' || c == '%' || c == '&')
{
sp++;
sb.Append(c);
}
//else if (!char.IsLetter(c))
//{
// sb.Append(c);
//}
}
if (num == 0 || sp == 0)
{
return "-1";
}
else
return sb.ToString();
}
}
}
====================================================================
77.
//program.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace oops2
{
class Program
{
static void Main(string[] args)
{
String input1 = Console.ReadLine();
String input2 = Console.ReadLine();
int ret = UserProgramCode.calcFrequency(input1, input2);
Console.WriteLine(ret);
//Console.WriteLine(input1.ToLower());
}
}
}
//UserProgramCode.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace oops2
{
class UserProgramCode
{
public static int calcFrequency(string input1, string input2)
{
StringBuilder sb = new StringBuilder();
int val = 0;
String[] arr = input1.Split(' ');
foreach (String a in arr)
{
sb.Append(a.ToLower());
}
int len = arr.Length;
for (int i = 0; i < len; i++)
{
String s = arr[i];
for (int j = i + 1; j < len; j++)
{
if (s.Equals(arr[j]))
{
val++;
return -1;
}
}
}
if (val == 0)
{
int count = 0;
StringBuilder sb1 = new StringBuilder();
String linput1 = input1.ToLower();
String linput2 = input2.ToLower().Replace('.',' ');
// Console.WriteLine(linput2);
String[] l = linput2.Split(' ');
foreach (String a in l)
{
sb1.Append(a);
}
len = sb.Length;
int len2 = sb1.Length;
// Console.WriteLine(len + "" + len2);
for (int i = 0; i < len2; i++)
{
if(i<len2-len)
{
// Console.WriteLine(i+","+len);
// Console.WriteLine(sb);
// Console.WriteLine(sb1);
String sub = sb1.ToString().Substring(i, len);
if (sub.Equals(sb.ToString()))
{
count++;
}
}
}
if (count == 0)
return -2;
else
return count;
}
return 0;
}
}
}
===================================================================================
=====
78.
//program.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace oops2
{
class Program
{
static void Main(string[] args)
{
int k,n;
k = int.Parse(Console.ReadLine());
String[] arr = new String[k];
for (int i = 0; i < k; i++)
{
arr[i] = Console.ReadLine();
}
n = int.Parse(Console.ReadLine());
String ret = UserProgramCode.formString(arr, n);
Console.WriteLine(ret);
}
}
//UserProgramCode.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace oops2
{
class UserProgramCode
{
public static string formString(string[] input1, int input2)
{
int len;
StringBuilder sb = new StringBuilder();
foreach (String a in input1)
{
if (a.Contains('#') || a.Contains('&') || a.Contains('%') ||
a.Contains('$'))
return "-1";
else
{
len = a.Length;
// Console.WriteLine(len + "," + input2);
if (input2 > len)
sb.Append('$');
else
{
// Console.WriteLine(a);
String c = a.Substring(input2-1,1);
// Console.WriteLine(c);
sb.Append(c);
}
}
}
return sb.ToString();
}
}
}
===================================================================================
==============
79.
//program.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace oops2
{
class Program
{
static void Main(string[] args)
{
int num;
num = int.Parse(Console.ReadLine());
String ret = UserProgramCode.wordForm(num);
Console.WriteLine(ret);
}
}
//UserProgramCode.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace oops2
{
class UserProgramCode
{
public static string wordForm(int n)
{
return _toText(n, true);
}
private static string _toText(long n, bool isFirst = false)
{
string result;
if (isFirst && n == 0)
{
result = "Zero";
}
else if (n < 0)
{
result = "Negative " + _toText(-n);
}
else if (n == 0)
{
result = "";
}
else if (n <= 9)
{
result = new[] { "One", "Two", "Three", "Four", "Five", "Six",
"Seven", "Eight", "Nine" }[n - 1] + " ";
}
else if (n <= 19)
{
result = new[] { "Ten", "Eleven", "Twelve", "Thirteen", "Fourteen",
"Fifteen", "Sixteen", "Seventeen", "Eighteen", "Nineteen" }[n - 10] + (isFirst ?
null : " ");
}
else if (n <= 99)
{
result = new[] { "Twenty", "Thirty", "Forty", "Fifty", "Sixty",
"Seventy", "Eighty", "Ninety" }[n / 10 - 2] + (n % 10 > 0 ? "-" + _toText(n % 10) :
null);
}
else if (n <= 999)
{
result = _toText(n / 100) + "Hundred " + _toText(n % 100);
}
else if (n <= 999999)
{
result = _toText(n / 1000) + "Thousand " + _toText(n % 1000);
}
else if (n <= 999999999)
{
result = _toText(n / 1000000) + "Million " + _toText(n % 1000000);
}
else
{
result = _toText(n / 1000000000) + "Billion " + _toText(n %
1000000000);
}
if (isFirst)
{
result = result.Trim();
}
return result;
}
}
}
=======================================================================
80.
//program.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace oops2
{
class Program
{
static void Main(string[] args)
{
String val = Console.ReadLine();
int num = int.Parse(Console.ReadLine());
String ret = UserProgramCode.repeatManipulateString(val, num);
Console.WriteLine(ret);
}
}
}
//UserProgramCode.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace oops2
{
class UserProgramCode
{
public static string repeatManipulateString(string input1, int input2)
{
StringBuilder sb = new StringBuilder();
int len = input1.Length;
if (len < 3)
return "Input value is insufficient";
if (input2 < 0)
return "Invalid Input";
if (len <= 5)
{
for (int i = 0; i < input2; i++)
{
sb.Append(input1.Substring(0,3));
}
return sb.ToString();
}
else if (len > 10)
{
return "Input value is too long";
}
else if (len >5)
{
for (int i = 0; i < input2; i++)
{
sb.Append(input1.Substring(len-3, 3));
}
return sb.ToString();
}
return " ";
}
}
}
81-100
81.a.)
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication13
{
class userprogramcode
{
public static string formWordwithLastLetters(string ip1)
{
string[] s= new string[ip1.Length];
char[] s1 = new char[ip1.Length];
string final="";
s = ip1.Split(' ');
int i = 0;
if (s.Length == 1)
return "-3";
foreach (string x in s)
{
s1[i] = x.ElementAt(x.Length - 1);
if (char.IsNumber(s1[i]))
return "-1";
else if (!char.IsLetter(s1[i]))
return "-2";
i++;
}
int j=0;
while (i > 0)
{
}
}
}
-----------------------------------------------------------------------------------
-------------------------------------------------------
81.b.)
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication13
{
class userprogramcode
{
public static string getString(string ip1, int ip2)
{
string s,final=ip1;
char s1;
for (int i = 0; i < ip1.Length; i++)
{
s1 = ip1[i];
if (char.IsNumber(s1))
return "-1";
else if (!char.IsLetter(s1))
return "-2";
}
s = ip1.Substring(ip1.Length - (ip2));
int j = ip2;
while (j > 0)
{
final = final + s;
j--;
}
return final;
}
}
class Program
{
static void Main(string[] args)
{
String x,y;
int k;
x = Console.ReadLine();
k = Convert.ToInt32(Console.ReadLine());
y = userprogramcode.getString(x,k);
Console.WriteLine(y);
}
}
}
-----------------------------------------------------------------------------------
-------------------------------------------------------
82.)
class UserProgramCode
{
public int check(int[] a,int len)
{
int r,cmax=0,cmin=0,count=0,i=0,rem=0,j=0;
StringBuilder sb = new StringBuilder();
foreach (int val in a)
{
i = 0; cmax = 0; cmin = 0;
int v = val;
if (val < 0)
return -2;
else
{
while (v > 0)
{
++j;
r = v % 10;
if (i == 0)
{
rem = r;
++i;
}
if (r == rem)
{
++cmin;
++cmax;
}
else if (r < rem)
{
++cmin;
rem = r;
}
else if (r > rem)
{
++cmax;
rem = r;
}
v = v / 10;
}
if (cmin == 1)
sb.Append("m");
if (cmax == 1)
sb.Append("M");
if (cmin == 1 || cmax == 1 )
{
++count;
}
else
return -1;
}
}
if (count == len)
{
//Console.WriteLine("true");
int counter = 0;
char odd = sb[1];
char even = sb[0];
if (!odd.Equals(even))
{
for (int ii = 0; ii < sb.Length; ii++)
{
if (ii % 2 == 0)
{
//Console.WriteLine("inside even pos");
if (sb[ii].Equals(even))
counter++;
else
return -1;
}
else
{
//Console.WriteLine("inside odd pos");
if (sb[ii].Equals(odd))
counter++;
else
return -1;
}
}
if (counter == count)
return 1;
}
else
return -1;
}
return 0;
}
}
-----------------------------------------------------------------------------------
-------------------------------------------------------
83.
//program.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace trial
{
class Program
{
static void Main(string[] args)
{
int n = int.Parse(Console.ReadLine());
String[] ar = new String[n];
for (int i = 0; i < n; i++)
{
ar[i] = Console.ReadLine();
}
String[] ret = UserProgramCode.orderStringElements(ar);
foreach (String a in ret)
{
Console.WriteLine(a);
}
}
}
}
//UserProgramCode.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
namespace trial
{
class UserProgramCode
{
public static string[] orderStringElements(string[] ar)
{
int len = ar[0].Length;
String pat = @"^[a-zA-Z]{"+len+"}$";
// Regex reg = new Regex(@"^[a-zA-Z]+$");
Regex reg1 = new Regex(pat);
String[] res = new String[1];
StringBuilder sb = new StringBuilder();
int n = ar.Length;
foreach (String aa in ar)
{
if (!reg1.IsMatch(aa))
{
res[0] = "Invalid String";
return res;
}
}
for (int i = 0; i < n; i++)
{
String a = ar[i];
Array.Sort(array, StringComparer.Ordinal);
return array;
}
}
}
-----------------------------------------------------------------------------------
-------------------------------------------------------
84.)
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication13
{
class userprogramcode
{
public static string getString(string ip1)
{
string[] final = new string[ip1.Length];
for (int j = 0; j < ip1.Length; j++)
final[j] = ip1[j].ToString();
string t1,ans="";
for (int j = 0; j < ip1.Length; j++)
if (!char.IsLetter(ip1[j]))
return "Invalid String";
if (final[0] != final[ip1.Length - 1])
{
t1 = final[0];
final[0] = final[ip1.Length - 1];
final[ip1.Length - 1] = t1;
for (int i = 0; i < ip1.Length; i++)
ans=ans+final[i];
}
else
ans = "No Change";
return ans;
}
}
class Program
{
static void Main(string[] args)
{
String x, y;
x = Console.ReadLine();
y = userprogramcode.getString(x);
Console.WriteLine(y);
}
}
}
-----------------------------------------------------------------------------------
-------------------------------------------------------
85.)
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication13
{
class userprogramcode
{
public static int sumMaxMin(int ip1, int ip2, int ip3)
{
int ans,a,b;
int[] t1 = new int[3];
t1[0] = ip1;
t1[1] = ip2;
t1[2] = ip3;
for (int i = 0; i < 3; i++)
if (t1[i] < 0)
return -1;
for (int i = 0; i < 2; i++)
{
for (int j = i + 1; j < 3; j++)
{
if (t1[i] == t1[j])
return -2;
}
}
a = t1.Max();
b = t1.Min();
ans = a + b;
return ans;
}
}
class Program
{
static void Main(string[] args)
{
int x,y,z,k;
x = Convert.ToInt32(Console.ReadLine());
y = Convert.ToInt32(Console.ReadLine());
z = Convert.ToInt32(Console.ReadLine());
// k = Convert.ToInt32(Console.ReadLine());
k =userprogramcode.sumMaxMin(x,y,z);
Console.WriteLine(k);
}
}
}
-----------------------------------------------------------------------------------
-------------------------------------------------------
86)
using System;
using System.Text.RegularExpressions;
namespace code1
{
class Program
{
static void Main(String[] args)
{
int n;
Regex reg = new Regex(@"([A-Za-z])$");
n = int.Parse(Console.ReadLine());
String[] input1 = new String[n];
String input2;
String[] output;
for (int i = 0; i < n; i++)
{
input1[i] = Console.ReadLine();
if (!reg.IsMatch(input1[i]))
{
Console.WriteLine("Invalid Input"); return;
}
}
input2 = Console.ReadLine();
if (reg.IsMatch(input2))
{
output = UserMainCode.getEmployee(input1, input2);
if (UserMainCode.j == 0)
Console.WriteLine("No Empployee for " + input2 + " designation");
else if (UserMainCode.j == n / 2)
{
Console.WriteLine("All employees belong to same " + input2 + " designation");
}
else
{
foreach (var item in output)
{
Console.WriteLine(item);
}
}
}
else
{
Console.WriteLine("Invalid Input");
}
}
}
-----------------------------------------------------------------------------------
---------
using System;
public class UserMainCode {
public static int j;
int n = input1.Length;
j = 0;
String[] temp=new String[n];
using System;
using System.Text.RegularExpressions;
namespace code1
{
class Program
{
static void Main(String[] args)
{
int n;
Regex reg = new Regex(@"([A-Za-z0-9])$");
n = int.Parse(Console.ReadLine());
String[] input1 = new String[n];
int input2;
int output;
for (int i = 0; i < n; i++)
{
input1[i] = Console.ReadLine();
if (!reg.IsMatch(input1[i]))
{
Console.WriteLine("-2"); return;
}
}
for (int i = 0; i <n; i++)
{
for (int j = i+1; j < n; j++)
{
if(input1[i].Equals(input1[j]))
{ Console.WriteLine("-1");}
}
}
input2 = int.Parse(Console.ReadLine());
}
-----------------------------------------------------------------------------------
-------
using System;
}
}
-----------------------------------------------------------------------------------
-------------------------------------------------------
//pg88
using System;
using System.Text.RegularExpressions;
namespace code1
{
class Program
{
static void Main(String[] args)
{
int input1;
int input2;
input1=int.Parse(Console.ReadLine());
input2 = int.Parse(Console.ReadLine());
UserMainCode.onlineSalesAmount(input1, input2);
}
}
}
-----------------------------------------------------------------------------------
--------
using System;
}
}
-----------------------------------------------------------------------------------
-------------------------------------------------------
89)
using System;
using System.Text.RegularExpressions;
namespace code1
{
class Program
{
static void Main(String[] args)
{
int n;
n = int.Parse(Console.ReadLine());
String[] input1=new String[n];
}
}
-----------------------------------------------------------------------------------
using System;
if (input1[i].Substring(2, 2) == "SP")
{
if (input1[i].Substring(0, 2) == "BP")
amount += (100*1.3);
else if (input1[i].Substring(0, 2) == "CH")
amount += (450 * 1.3);
else if (input1[i].Substring(0, 2) == "OS")
amount += (200 * 1.3);
else
{ Console.WriteLine("Invalid location Code"); return; }
}
else if (input1[i].Substring(2, 2) == "NP")
{
if (input1[i].Substring(0, 2) == "BP")
amount += (100);
else if (input1[i].Substring(0, 2) == "CH")
amount += (450);
else if (input1[i].Substring(0, 2) == "OS")
amount += (200);
else
{Console.WriteLine("Invalid location Code");return;}
}
else
{ Console.WriteLine("Invalid Postal Delivery"); return;}
}
Console.WriteLine("Jack spends Rs "+amount+" to send the greetings");
}
}
-----------------------------------------------------------------------------------
-------------------------------------------------------
90)
using System;
using System.Text.RegularExpressions;
namespace code1
{
class Program
{
}
}
}
using System;
}
else
{ Console.WriteLine("Invalid Time of Travel"); return -2; }
}
return (int)amount;
}
}
-----------------------------------------------------------------------------------
-------------------------------------------------------
91.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Collections;
namespace ConsoleApplication23
{
class UserProgramCode
{
public static int longestPalindrome(string s1)
{
string s = s1;
s = Regex.Replace(s, @"\s+", " ");
string[] s2 = s.Split(' ');
char[] a2=new char[100];
for(int i=0;i<s2.Length;i++)
{
for(int j=0;j<s2[i].Length;j++)
{
if(char.IsDigit(s2[i][j]))
{
return -1;
}
}
}
for (int i = 0; i < s2.Length; i++)
{
for (int j = 0; j < s2[i].Length; j++)
{
if (!char.IsLetter(s2[i][j]))
{
return -2;
}
}
}
a2[i1] = a1[k-1];
k--;
}
for (int j = 0; j < s2[i].Length; j++)
{
if (s2[i][j] == a2[j])
{
flag = 1;
}
else
{
break;
}
}
if (flag == 1)
{
return flag;
}
return 0;
string a;
a=Console.ReadLine();
int flag;
flag =longestPalindrome(a);
Console.WriteLine(flag);
}
}
}
-----------------------------------------------------------------------------------
-------------------------------------------------------
92.)
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace sumlargest92
{
class Program
{
Console.WriteLine("sum="+s);
}
}
}
-----------------------------------------------------------------------------------
-------------------------------------------------------
namespace ConsoleApplication2
{
class Program
{
static void Main(string[] args)
{
string str = Console.ReadLine();
Console.WriteLine(UserProgramCode.nextString(str));
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Collections;
namespace ConsoleApplication2
{
class UserProgramCode
{
public static string nextString(string str)
{
ArrayList vowel_small = new ArrayList();
ArrayList vowel_caps = new ArrayList();
vowel_small.Add('a');
vowel_small.Add('e');
vowel_small.Add('i');
vowel_small.Add('o');
vowel_small.Add('u');
vowel_caps.Add('A');
vowel_caps.Add('E');
vowel_caps.Add('I');
vowel_caps.Add('O');
vowel_caps.Add('U');
char[] inp = str.ToCharArray();
char[] out1 = new char[str.Length];
}
else if (inp[i] == 90 || inp[i] == 122)
{
if (inp[i] == 90)
out1[i]='A';
else
out1[i] = 'a';
}
else
{
if (inp[i] >= 65 && inp[i] <= 90)
{
if (inp[i] > 85)
out1[i] = 'A';
else
{
foreach (char che in vowel_caps)
{
if (che > inp[i])
{
out1[i] = che;
break;
}
}
}
}
else
{
if (inp[i] > 117)
out1[i] = 'a';
else
{
foreach (char che in vowel_small)
{
if (che > inp[i])
{
out1[i] = che;
break;
}
}
}
}
}
}
string output=null;
foreach (char c in out1)
{
output += c.ToString();
}
return output;
}
}
}
-----------------------------------------------------------------------------------
-------------------------------------------------------
94.Power of 2
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Collections;
namespace ConsoleApplication23
{
class UserProgramCode
{
public static int twoPower(int input1)
{
int i1 = input1;
int n=2;
int i = 1;
int sum=1;
int val=0;
ArrayList al = new ArrayList();
while (i < i1)
{
if ((sum * n) == i1)
{
val = i;
break;
}
sum = sum * n;
al.Add(sum);
i++;
}
return val;
}
static void Main(string[] args)
{
int i;
i = int.Parse(Console.ReadLine());
int val1;
val1 = twoPower(i);
if (val1 > 0)
Console.WriteLine(val1);
else
Console.WriteLine(-1);
}
}
}
-----------------------------------------------------------------------------------
-------------------------------------------------------
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Collections;
namespace ConsoleApplication23
{
class UserProgramCode
{
public static string stringEqualCheck(string input1, string input2, int
input3)
{
string i1, i2;
int i3;
i1 = input1;
char[] i11=i1.ToCharArray();
i2 = input2;
char[] i22=i2.ToCharArray();
i3 = input3;
foreach (char ch in i11)
{
if (char.IsDigit(ch))
{
Console.WriteLine( "invalid input");
}
if (!char.IsLetter(ch))
{
Console.WriteLine("invalid input");
}
}
foreach (char ch in i22)
{
if (char.IsDigit(ch))
{
Console.WriteLine("invalid input");
}
if (!char.IsLetter(ch))
{
Console.WriteLine("invalid input");
}
}
if(i3>i1.Length)
{
Console.WriteLine("invalid input");
}
else if (i3 > i2.Length)
{
Console.WriteLine("invalid input");
}
return "string";
}
static void Main(string[] args)
{
string s1, s2;
int index;
s1 = Console.ReadLine();
s2 = Console.ReadLine();
index = int.Parse(Console.ReadLine());
string disp;
disp = stringEqualCheck(s1, s2, index);
}
}
}
-----------------------------------------------------------------------------------
-------------------------------------------------------
96.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication96
{
class Program
{
static void Main(string[] args)
{
int n;
n = Convert.ToInt16(Console.ReadLine());
UserProgramCode.findNumber(n);
}
}
class UserProgramCode
{
int i = 0;
int count = 0;
if (input1 > 0)
{
while (1 == 1)
{
int x = ++i;
int z = x;
string k = Convert.ToString(x);
int l = k.Length;
int cc = 0;
for (int j = 0; j < l; j++)
{
int a = x % 10;
int b = x / 10;
x = b;
if (a == 3 || a == 4)
{
cc++;
}
else
break;
}
if (cc == l)
count++;
if (input1 == count)
{
Console.WriteLine(z);
break;
}
}
}
else
Console.WriteLine(-1);
}
}
}
===================================================================================
==
97.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;
namespace ConsoleApplication97
{
class Program
{
static void Main(string[] args)
{
string a, b;
a = Console.ReadLine();
b=UserProgramCode.rearrangeCase(a);
Console.WriteLine(b);
}
}
class UserProgramCode
{
static char cf;
public static string rearrangeCase(string input1)
{
int l = input1.Length;
// string a=Convert.ToString();
int c1 = 0,c3=0;
}
for (int i = 0; i < l; i++)
{
if (input1[i] == char.ToUpper(cf))
{
a1.Append(cf);
}
else if (input1[i] == char.ToLower(cf))
{
a2.Append(char.ToLower(cf));
}
else
{
a3.Append(input1[i]);
}
}
}
return (a1.ToString() + "" + a3.ToString() + "" + a2.ToString());
}
}
}
===================================================================================
==
98.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;
namespace ConsoleApplication98
{
class Program
{
static void Main(string[] args)
{
int l=1;
int[] a = new int[30];
for (int i = 0; i <= l; i++)
{
a[i] = Convert.ToInt16(Console.ReadLine());
l = a[0];
}
UserProgramCode.findRepeatedIntegers(a);
}
}
class UserProgramCode
{
public static void findRepeatedIntegers(int[] a)
{
ArrayList a1 = new ArrayList();
int flag = 0;
for (int i = 1; i <= a[0]; i++)
{
if (a[i] >= 0)
{
int c = 0;
for (int j = 1; j <= a[0]; j++)
{
if (a[i] == a[j])
c++;
}
if (c > 1)
{
if (!(a1.Contains(a[i])))
a1.Add(a[i]);
}
}
else
{
flag = 1;
break;
}
}
if (flag == 0)
{
a1.Sort();
int c1 = 0;
foreach (int i in a1)
c1++;
if (c1 == 0)
Console.WriteLine("No repeated numbers");
else
{
foreach (int i in a1)
{
Console.WriteLine(i);
}
}
}
else
Console.WriteLine("Array contains negative numbers");
}
}
}
===================================================================================
==
99.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication99
{
class Program
{
static void Main(string[] args)
{
int[] a = new int[30];
int l = 1;
for (int i = 0; i <=l+1; i++)
{
a[i] = Convert.ToInt16(Console.ReadLine());
l = a[0];
}
int b = UserProgramCode.findExistence(a);
if(b==1)
Console.WriteLine("present");
else if(b==0)
Console.WriteLine("not present");
else
Console.WriteLine("Non Positive");
}
}
class UserProgramCode
{
public static int findExistence(int[] a)
{
int c = 0;
int flag=0;
for (int i = 1; i <= a[0]; i++)
{
if (a[i] >= 0)
{
if (a[i] == a[a[0] + 1])
c++;
}
else
{
flag = 1;
break;
}
}
if (flag == 0)
{
if (c > 0)
return 1;
else
return 0;
}
else
return -1;
}
}
===================================================================================
==
100.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication100
{
class Program
{
static void Main(string[] args)
{
int a;
a = int.Parse(Console.ReadLine());
int c = UserProgramCode.findLargestDigit(a);
if(c==-1)
Console.WriteLine("Negative Number");
else
Console.WriteLine(c);
}
}
class UserProgramCode
{
public static int findLargestDigit(int b)
{
if (b >= 0)
{
string a = b.ToString();
int l = a.Length;
int c = 0;
for (int i = 0; i < l; i++)
{
int x = b / 10;
int y = b % 10;
b = x;
if (y >= c)
{
c = y;
}
}
return c;
}
else
return (-1);
}
}
}
===================================================================================
==