Wipro PRP
Wipro PRP
which had many words whose one character was missing ie. one character in the word was replaced by an
underscore. For e.g. “Fi_ er”. He also found thin strips of paper which had a group of words separated by colons,
for e.g. “Fever:filer:Filter: Fixer:fiber:fibre:tailor:offer”. He could figure out that the word whose one character
was missing was one of the possible words from the thin strips of paper. Detective Bakshi has approached you (a
computer programmer) asking for help in identifying the possible words for each incomplete word.
You are expected to write a function to identify the set of possible words.
The function identity PossibleWords takes two strings as input, where input1 contains the incomplete word, and
input2 is the string containing a set of words separated by colons
The function is expected to find all the possible words from input2 that can replace the incomplete word input1,
and then return the final output string in the format specified below See below examples carefully to understand
the format of input1, input2 and output
● Output string should contain the set of all possible words that can replace the incomplete word in input1
● all words in the output string should appear in the order in which they appeared in input2, i.e. in the above
example we have FILER followed by FIXER followed by FIBER.
● While searching for input1 in input2, the case of the letters are ignored, i.e Fi er matches with filer as well as
Fixer as well as "fiber”.
● IMPORTANT: If none of the words in input2 are possible candidates to replace input1, the output string should
be “ERROR-009”.
using System;
string input1=Console.ReadLine();
string input2=Console.ReadLine();
input1=input1.ToUpper();
input2=input2.ToUpper();
int i,j;
for(i=0;i<words.Length;i++)
word = words[i];
if(input1.Length==word.Length)
{
for(j=0;j<input1.Length;j++)
if((input1[j]!='_')&&(input1[j]!=word[j]))
break;
if(j==input1.Length)
res=res + word+":";
Console.WriteLine(res.Length==0?"ERROR-009":res.Substring(0,res.Length-1));
ALTERNATE ADD SUM Given a number N (1<=N<=10000), and an option opt=1 or 2, find the result as per below
rules, If opt=1, Result= N-(N-1)+(N-2) - (N-3) +(N-4) ......till 1 If opt=2 Result= N+(N-1)- (N-2) + (N-3) - (N-4)..... till 1
Example1: IfN = 6, and opt=1 Result =6-5+4-3+2-1=3 Example2 If N = 6, and opt=2 Result =6+5-4+3-2+1= 9 The
function prototype should be as belowint AddSub(int N, int opt);
Code:
using System;
int N=Int32.Parse(Console.ReadLine());
int opt=Int32.Parse(Console.ReadLine());
int sum=0;
sum+=N;
N=N-1;
if(opt==2)
if(N%2==0)
while(N>0)
if(N%2==0)
sum+=N;
else
sum-=N;
N--;
else
while(N>0)
if(N%2==0)
sum-=N;
else
sum+=N;
N--;
else
if(N%2==0)
while(N>0)
if(N%2==0)
sum-=N;
else
sum+=N;
N--;
else
while(N>0)
if(N%2==0)
sum+=N;
else
sum-=N;
N--;
Console.WriteLine(sum);
FIND SUMEET SUM (Model-1) Given 5 input numbers, Sumeet has to find the sum of the smallest numbers that
can be produced using 2 digits from each of the above 5 numbers. Understanding Question: We are given five
numbers and we have to find the smallest 2-digit numbers from given five numbers i.e., For example take a
number 54110. We have to find the smallest 2-digit number that can be formed. In the first Iteration we will get 0
as the smallest number when considered as 1-digit number but we need 2-digit number so in another iteration
we’ll get 1 as smallest number so from this the smallest 2-digit number that can be formed from given number
54110 is 01.
In the similar manner we’re given 5 numbers and we have to find the smallest 2-digit number from all those
inputs given and we’ve to find the sum of all smallest 2-digit numbers acquired.
Input1 – 23792 – From these the smallest number that can be formed is 22.
Input2 – 37221 – From these the smallest number that can be formed is 12.
Input3 – 10270 – From these the smallest number that can be formed is 00.
Input4 – 73391 – From these the smallest number that can be formed is 13.
Input5 – 12005 – From these the smallest number that can be formed is 00.
The second part of our task is to find the sum of all these smallest 2-digit numbers and the result is 47.
Input2 – 105 – From these the smallest number that can be formed is 01.
Input3 – 37943 – From these the smallest number that can be formed is 33.
Input4 – 95278 – From these the smallest number that can be formed is 25.
Input5 – 27845 – From these the smallest number that can be formed is 24.
The second part of our task is to find sum of all these smallest 2-digit numbers and the result is 107.
using System;
int input1=Convert.ToInt32(Console.ReadLine());
int input2=Convert.ToInt32(Console.ReadLine());
int input3=Convert.ToInt32(Console.ReadLine());
string x=input1.ToString();
string y=input2.ToString();
string z=input3.ToString();
char[] ch1=x.ToCharArray();
Array.Sort(ch1);
char[] ch2=y.ToCharArray();
Array.Sort(ch2);
char[] ch3=z.ToCharArray();
Array.Sort(ch3);
int l1=ch1.Length;
int l2=ch2.Length;
int l3=ch3.Length;
string a=Convert.ToString(ch1[l1-1])+Convert.ToString(ch1[l1-2]);
string b=Convert.ToString(ch2[l2-1])+Convert.ToString(ch2[l2-2]);
string c=Convert.ToString(ch3[l3-1])+Convert.ToString(ch3[l3-2]);
int num1=Int32.Parse(a);
Console.WriteLine(num1);
int num2=Int32.Parse(b);
Console.WriteLine(num2);
int num3=Int32.Parse(c);
Console.WriteLine(num3);
int sum=0;
sum=num1+num2+num3;
Console.WriteLine(sum);
FIND SUMEET SUM (Model-2) FindSumeetSum: Sum of smallest 3- digit numbers from given 5 numbers Given 5
input numbers, Sumeet has to find the sum of the smallest numbers that can be produced using 3 digits from each
of the above 5 numbers
Example-1 If the 5 input numbers are 23792,37221,10270,73391 and 12005 The smallest numbers that can be
produced using 3 digits from each of these are 223,122,001,133 and 001 respectively, and the sum of these
smallest numbers will be 480. Therefore, the expected result is 480
Example-2 If the 5 input numbers are 26674,105,37943,95278 and 27845, The smallest numbers that can be
produced using 3 digits from each of these are 246,015,334,257 and 245 respectively, and the sum of these
smallest numbers will be 1097. Therefore, the expected result is 1097.
NOTE- All the given 5 numbers will be >=100 and <=99999 Function prototype is as belowInt findSumeetSum(int
input1,int input2,int input3,int input4,int input5)
using System;
int input1=Convert.ToInt32(Console.ReadLine());
int input2=Convert.ToInt32(Console.ReadLine());
int input3=Convert.ToInt32(Console.ReadLine());
int input4=Convert.ToInt32(Console.ReadLine());
int input5=Convert.ToInt32(Console.ReadLine());
string x=input1.ToString();
string y=input2.ToString();
string z=input3.ToString();
string a=input4.ToString();
string b=input5.ToString();
char[] ch1=x.ToCharArray();
Array.Sort(ch1);
char[] ch2=y.ToCharArray();
Array.Sort(ch2);
char[] ch3=z.ToCharArray();
Array.Sort(ch3);
char[] ch4=a.ToCharArray();
Array.Sort(ch4);
char[] ch5=b.ToCharArray();
Array.Sort(ch5);
string c=Convert.ToString(ch1[0])+Convert.ToString(ch1[1])+Convert.ToString(ch1[2]);
string d=Convert.ToString(ch2[0])+Convert.ToString(ch2[1])+Convert.ToString(ch2[2]);
string e=Convert.ToString(ch3[0])+Convert.ToString(ch3[1])+Convert.ToString(ch3[2]);
string f=Convert.ToString(ch4[0])+Convert.ToString(ch4[1])+Convert.ToString(ch4[2]);
string g=Convert.ToString(ch5[0])+Convert.ToString(ch5[1])+Convert.ToString(ch5[2]);
int num1=Int32.Parse(c);
int num2=Int32.Parse(d);
int num3=Int32.Parse(e);
int num4=Int32.Parse(f);
int num5=Int32.Parse(g);
int sum=0;
sum=num1+num2+num3+num4+num5;
Console.WriteLine(sum);
FIND SUMEET SUM (Model-3) FindSumeetSum: Sum of largest 3-digit numbers from given 5 numbers Given 5
input numbers, Sumeet has to find the sum of the largest numbers that can be produced using 3 digits from each
of the above 5 numbers.
Example-1 If the 5 input numbers are 23792,37221,10270,73391 and 12005, The largest numbers that can be
produced using 3 digits from each of these are 973,732,721,973 and 521 respectively and the sum of these largest
numbers will be 3920. Therefore, the expected result is 3920.
Example-2 If the 5 input numbers are 26674,105,37943,95278 and 27845 The largest numbers that can be
produced using 3 digits from each of these are 766,510,974,987 and 875 respectively and the sum of these largest
numbers will be 4112. Therefore, the expected result is 4112.
NOTE:- All the given 5 numbers will be >=100 and <=99999 Function prototype is as below – Int
findSumeetSum(int input1,int input2,int input3,int input4,int input5)
using System;
int input1=Convert.ToInt32(Console.ReadLine());
int input2=Convert.ToInt32(Console.ReadLine());
int input3=Convert.ToInt32(Console.ReadLine());
int input4=Convert.ToInt32(Console.ReadLine());
int input5=Convert.ToInt32(Console.ReadLine());
string x=input1.ToString();
int l1=x.Length;
string y=input2.ToString();
int l2=y.Length;
string z=input3.ToString();
int l3=z.Length;
string a=input4.ToString();
int l4=a.Length;
string b=input5.ToString();
int l5=b.Length;
char[] ch1=x.ToCharArray();
Array.Sort(ch1);
char[] ch2=y.ToCharArray();
Array.Sort(ch2);
char[] ch3=z.ToCharArray();
Array.Sort(ch3);
char[] ch4=a.ToCharArray();
Array.Sort(ch4);
char[] ch5=b.ToCharArray();
Array.Sort(ch5);
string c=Convert.ToString(ch1[l1-1])+Convert.ToString(ch1[l1-2])+Convert.ToString(ch1[l1-3]);
string d=Convert.ToString(ch2[l2-1])+Convert.ToString(ch2[l2-2])+Convert.ToString(ch2[l2-3]);
string e=Convert.ToString(ch3[l3-1])+Convert.ToString(ch3[l3-2])+Convert.ToString(ch3[l3-3]);
string f=Convert.ToString(ch4[l4-1])+Convert.ToString(ch4[l4-2])+Convert.ToString(ch4[l4-3]);
string g=Convert.ToString(ch5[l5-1])+Convert.ToString(ch5[l5-2])+Convert.ToString(ch5[l5-3]);
int num1=Int32.Parse(c);
int num2=Int32.Parse(d);
int num3=Int32.Parse(e);
int num4=Int32.Parse(f);
int num5=Int32.Parse(g);
int sum=0;
sum=num1+num2+num3+num4+num5;
Console.WriteLine(sum);
//4112
You are provided with TWO words. You are expected to split each word into THREE parts each, and create a
password using the below rule –
Password = first part of word 2 + first part of word1 + third part of word1 + third part of word 2 For splitting a
given word into three parts the below approach should be used If word= "ABC", then part1-A part2=B and part3-C
If word= "ABCD", then part1=A part2=BC and part 3=D
i.e.,
1) If the length of the given word can be equally divided into three parts, then each part gets the same number of
letters (as seen in above examples of "ABC" and "ABCDEF")
2) If the length of the given word cannot be equally divided into three parts, then the center part i.e., part2 gets
the extra number of characters (as seen in rest of the above examples)
Example 1:
input1="WIPRO"
Explanation - The three parts of WIPRO will be "W", "IPR" and "O"
So, Password = First part of word 2 + First part of word 1+ Third part of word 1 + Third part of word2 =TECH + W +
O + GIES = TECHWOGIES
Explanation –
So, Password = First part of word 2 + First part of word 1+ Third part of word 1 + Third part of word2
= LE + MA + NE + NG = LEMANENG
using System;
string str1=Console.ReadLine();
string str2=Console.ReadLine();
int l1=str1.Length;
int l2=str2.Length;
string[] words={str1,str2};
string password="";
for(int i=0;i<2;i++)
int l=words[i].Length;
res[i,0]=words[i].Substring(0,l/3);
res[i,1]=words[i].Substring(l/3,l-l/3);
res[i,2]=words[i].Substring(l-l/3);
password=res[1,0]+res[0,0]+res[0,2]+res[1,2];
Console.WriteLine(password);
You are provided with TWO words. You are expected to split each word into THREE parts each, and create a
password using the below rule – Password = Second part of word 1+ Second part of word 2 + First part of word 2
For splitting a given word into three parts the below approach should be used If word= "ABC",
If the length of the given word can be equally divided into three parts, then each part gets the same number of
letters (as seen in above examples of "ABC" and "ABCDEF")
2) If the length of the given word cannot be equally divided into three parts, then the center part i.e., part2 gets
the extra number of characters (as seen in rest of the above examples) Let us now look at the below examples
Example 1:
Explanation - The three parts of WIPRO will be "W", "IPR" and "O"
So, Password = Second part of word 1+ Second part of word 2 + First part of word 2 = IPR + NOLO + TECH =
IPRNOLOTECH
Example 2:
Explanation - The three parts of MACHINE will be "MA", "CHI" and "NE"
So, Password = Second part of word 1+ Second part of word 2 + First part of word 2 = LE + MA + NE + NG =
LEMANENG
using System;
public class Program
string str1=Console.ReadLine();
string str2=Console.ReadLine();
int l1=str1.Length;
int l2=str2.Length;
string[] words={str1,str2};
string password="";
for(int i=0;i<2;i++)
int l=words[i].Length;
res[i,0]=words[i].Substring(0,l/3);
res[i,1]=words[i].Substring(l/3,(l-l/3)-l/3);
res[i,2]=words[i].Substring(l-l/3);
password=res[0,1]+res[1,1]+res[1,0];
Console.WriteLine(password);
Example 1: input1="WIPRO"
input 2="TECHNOLOGIES"
Explanation - The three parts of WIPRO will be "WI", "P" and "RO"
So, Password = Second part of word1+ Third part of word 2 + First part of word1 + First part of word 2 =P + GIES +
WI + TECH = PGIESWITECH
Example 2:
input="MACHINE"
input 2="LEARNING"
Explanation - The three parts of MACHINE will be "MA", "CHI" and "NE"
So, Password = Second part of word1+ Third part of word 2 + First part of word1 + First part of word 2 = CHI + ING
+ MA + LEA = CHIINGMALEA
Code:
using System;
string str1=Console.ReadLine();
string str2=Console.ReadLine();
int l1=str1.Length;
int l2=str2.Length;
string[] words={str1,str2};
string password="";
for(int i=0;i<2;i++)
if(len%3==0 || len%3==1)
res[i,2] = words[i].Substring(len-len/3);
}
else
res[i,2] = words[i].Substring(len-len/3-1);
for(int a=0;a<2;a++)
for(int b=0;b<3;b++)
Console.WriteLine(res[a,b]);
password=(res[0,1]+res[1,2]+res[0,0]+res[1,0]);
Console.WriteLine(password);
Example 1:
input1="WIPRO"
input 2="TECHNOLOGIES"
Explanation - The three parts of WIPRO will be "WI", "P" and "RO"
So, Password = Third part of word2 + Second part of word1 + Second part of word2 + First part of word1
= GIES + P + NOLO + WI
= GIESPNOLOWI
Example 2:
input="MACHINE"
Input 2="LEARNING"
So, Password = Third part of word2 + Second part of word1 + Second part of word2 + First part of word1
= ING + CHI + RN + MA
= INGCHIRNMA
using System;
string str1=Console.ReadLine();
string str2=Console.ReadLine();
int l1=str1.Length;
int l2=str2.Length;
string[] words={str1,str2};
string password="";
for(int i=0;i<2;i++)
if(len%3==0 || len%3==1)
res[i,2] = words[i].Substring(len-len/3);
else
{
res[i,0] = words[i].Substring(0, len/3+1);
res[i,2] = words[i].Substring(len-len/3-1);
for(int a=0;a<2;a++)
for(int b=0;b<3;b++)
Console.WriteLine(res[a,b]);
password=(res[1,2]+res[0,1]+res[1,1]+res[0,0]);
Console.WriteLine(password);
Example 1:
input1="WIPRO"
input 2="TECHNOLOGIES"
Explanation –
So, Password = First part of word2 + First part of word1 + Third part of word1 + Third part of word2
= TECH + WI + RO + GIES
= TECHWIROGIES
Example 2:
input="MACHINE"
input 2="LEARNING"
Explanation –
The three parts of MACHINE will be "MA", "CHI" and "NE"
So, Password = First part of word2 + First part of word1 + Third part of word1 + Third part of word2
= LEA + MA + NE + ING
= LEAMANEING
using System;
string str1=Console.ReadLine();
string str2=Console.ReadLine();
int l1=str1.Length;
int l2=str2.Length;
string[] words={str1,str2};
string password="";
for(int i=0;i<2;i++)
if(len%3==0 || len%3==1)
res[i,2] = words[i].Substring(len-len/3);
else
{
res[i,0] = words[i].Substring(0, len/3+1);
res[i,2] = words[i].Substring(len-len/3-1);
for(int a=0;a<2;a++)
for(int b=0;b<3;b++)
Console.WriteLine(res[a,b]);
password=(res[1,0]+res[0,0]+res[0,2]+res[1,2]);
Console.WriteLine(password);
Each of these are 4 digits numbers within >=1000 and <=9999 i.e.,
Key = Sum of Largest digits of each number + Sum of Second Largest digits of each number
For Example,
using System;
int input1=Convert.ToInt32(Console.ReadLine());
int input2=Convert.ToInt32(Console.ReadLine());
int input3=Convert.ToInt32(Console.ReadLine());
string str1=input1.ToString();
string str2=input2.ToString();
string str3=input3.ToString();
char[] ch1=str1.ToCharArray();
Array.Sort(ch1);
char[] ch2=str2.ToCharArray();
Array.Sort(ch2);
char[] ch3=str3.ToCharArray();
Array.Sort(ch3);
String L1=Convert.ToString(ch1[ch1.Length-1]);
String L2=Convert.ToString(ch2[ch2.Length-1]);
String L3=Convert.ToString(ch3[ch3.Length-1]);
String l1=Convert.ToString(ch1[ch1.Length-2]);
String l2=Convert.ToString(ch2[ch2.Length-2]);
String l3=Convert.ToString(ch3[ch3.Length-2]);
int
key=Convert.ToInt32(L1)+Convert.ToInt32(L2)+Convert.ToInt32(L3)+Convert.ToInt32(l1)+Convert.ToInt32(l2)+Con
vert.ToInt32(l3);
Console.WriteLine(key);
Each of these are four digit numbers within the range >=1000 and <=9999
you are expected to find the key using the below formula
Key=
using System;
int input1=Convert.ToInt32(Console.ReadLine());
int input2=Convert.ToInt32(Console.ReadLine());
int input3=Convert.ToInt32(Console.ReadLine());
int th1=input1/1000;
int h1=(input1/100)%10;
int t1=(input1/10)%10;
int u1=input1%10;
int th2=input2/1000;
int h2=(input2/100)%10;
int t2=(input2/10)%10;
int u2=input2%10;
int th3=input3/1000;
int h3=(input3/100)%10;
int t3=(input3/10)%10;
int u3=input3%10;
int minth=Math.Min(Math.Min(th1,th2),th3);
int maxh=Math.Max(Math.Max(h1,h2),h3);
int mint=Math.Min(Math.Min(t1,t2),t3);
int maxu=Math.Max(Math.Max(u1,u2),u3);
int key=minth*1000+maxh*100+mint*10+maxu;
Console.WriteLine(key);
}
FIND KEY (Model-3):
Each of these are four digit numbers within the range >=1000 and <=9999
you are expected to find the key using the below formula
Key=[LARGEST digit in the thousands place of all three numbers][smallest digit in the hundreds place of all the
three numbers]
using System;
int input1=Convert.ToInt32(Console.ReadLine());
int input2=Convert.ToInt32(Console.ReadLine());
int input3=Convert.ToInt32(Console.ReadLine());
int th1=input1/1000;
int h1=(input1/100)%10;
int t1=(input1/10)%10;
int u1=input1%10;
int th2=input2/1000;
int h2=(input2/100)%10;
int t2=(input2/10)%10;
int u2=input2%10;
int th3=input3/1000;
int h3=(input3/100)%10;
int t3=(input3/10)%10;
int u3=input3%10;
int minth=Math.Max(Math.Max(th1,th2),th3);
int maxh=Math.Min(Math.Min(h1,h2),h3);
int mint=Math.Max(Math.Max(t1,t2),t3);
int maxu=Math.Min(Math.Min(u1,u2),u3);
int key=minth*1000+maxh*100+mint*10+maxu;
Console.WriteLine(key);
Mohan has received an array of numbers The numbers in this array are special because each number consists of
two parts -a “KEY” part and a “NEXT ADDRESS” part For example, if the number in the array is 411, the leftmost
digit in the number is “4” is the “KEY part and all the remaining digits in number be “11 form the “NEXT ADDRESS
part. Mohan’s task is to start from the first array element, pick the “KEY”part go to the “NEXT ADDRESS array
element pick Its “KEY” part, go to the “NEXT ADDRESS array element, pick its “KEY part, and continue this cycle
the encounters a negative number While traversing through the array in this fashion, we need to perform an
alternate addition and subtraction of the KEYS. The result of alternate addition and subtraction of all the keys is
the expected final result. Note that we should stop traversing (traveling) through the array when a negative
number is encountered
(See Examples 1 and 2 below) Important: If the array does NOT contain any negative number, the result should be
the largest number in the array (See Example 3 below) Help Mohan by writing the code to find the FINAL Result.
Input1 represents the array of numbers, and input2 represents the number of elements in the array.
Example 1 – If the array input 1 is 74 -56 15 71 92 23 and input2 is 6 First array element = 74
(NOTE THAT ARRAY ELEMENT ADDRESS STARTS FROM 0, SO 4th element is 92)
Here, KEY = 5 NEXT ADDRESS -STOP (because we have reached a negative number).
FINAL RESULT = Alternatively Add and Subtract the keys = 7+9-1+ 2-7+5= 15
using System;
int input2=Convert.ToInt32(Console.ReadLine());
int[] input1={74,-56,15,71,92,23};
int i, flag=0;
for(i=0;i<input2;i++)
if(input1[i]<0)
flag=1;
if(input1[i]>max)
max=input1[i];
if(flag==0)
Console.WriteLine(max);
i=0;
if(input1[i]<0)
flag=0;
input1[i]*=-1;
digits = (int)(Math.Log10(input1[i])+1);
key = (int)input1[i]/power;
if(i==0)
res = key;
else
i = input1[i]%power;
Console.WriteLine(res);
}
}
Example 1-
and input2 is 6
4th array element 29 (NOTE THAT ARRAY ELEMENT ADDRESS STARTS FROM 0, So 4th element is 29)
Here, KEY=5 NEXT ADDRESS - STOP (because we have reached a negative number) FINAL RESULT = Alternately
subhead and Add the key 7-9+1-2+7-5=1
First array element 47 Here KEY 7 NEXT ADDRESS=4 4th array element is 29
Here we see that the array does NOT contain any negative number, so the result should be calculated as the
smallest number in the array FINAL RESULT 12
using System;
int input2=Convert.ToInt32(Console.ReadLine());
int[] input1={47,65,51,12,29,32,54};
int flag=0,k=0,key,add;
for(int i=0;i<input2;i++)
{
if(input1[i]<0)
flag=1;
break;
if(flag==0)
Array.Sort(input1);
Console.WriteLine(input1[0]);
else
key=input1[0]%10;
a[k++]=key;
input1[0]=input1[0]/10;
add=input1[0];
while(input1[add]>0)
key=input1[add]%10;
a[k++]=key;
input1[add]=input1[add]/10;
add=input1[add];
a[k++]=-(input1[add]%10);
int sum=0;
for(int i=0;i<k;i++)
if(i%2==0)
sum+=a[i];
else
sum-=a[i];
Console.WriteLine(sum);
}
we see that there are THREE stable numbers i.e 12,1313 and 678 and TWO unstable numbers i.e 122 and 898
(2*10)+3=23
using System;
int input1=Convert.ToInt32(Console.ReadLine());
int input2=Convert.ToInt32(Console.ReadLine());
int input3=Convert.ToInt32(Console.ReadLine());
int input4=Convert.ToInt32(Console.ReadLine());
int input5=Convert.ToInt32(Console.ReadLine());
int[] num={input1,input2,input3,input4,input5};
for(i=0;i<5;i++)
int temp=num[i];
int maxf=0;
while(temp!=0)
int r = temp%10;
freq[r]++;
temp/=10;
if(freq[r]>maxf)
maxf=freq[r];
}
for(j=0;j<10;j++)
break;
if(j==10)
stable++;
else
unstable++;
Console.WriteLine(unstable*10 + stable);
using System;
int input1=Convert.ToInt32(Console.ReadLine());
int input2=Convert.ToInt32(Console.ReadLine());
int input3=Convert.ToInt32(Console.ReadLine());
int input4=Convert.ToInt32(Console.ReadLine());
int input5=Convert.ToInt32(Console.ReadLine());
int[] num={input1,input2,input3,input4,input5};
int temp=num[i];
int maxf=0;
while(temp!=0)
int r = temp%10;
freq[r]++;
temp/=10;
if(freq[r]>maxf)
maxf=freq[r];
for(j=0;j<10;j++)
break;
if(j==10)
stable++;
else
unstable++;
Console.WriteLine(stable*10 + unstable);
we see that there are THREE stable numbers i.e 12,1313 and 678 and
o,the password should be=Maximum of all stable numbers+Minimum of all Unstable numbers=1313+122=1435
using System;
//12,1313,122,678,898
//numbers=1313+122=1435
int input1=Convert.ToInt32(Console.ReadLine());
int input2=Convert.ToInt32(Console.ReadLine());
int input3=Convert.ToInt32(Console.ReadLine());
int input4=Convert.ToInt32(Console.ReadLine());
int input5=Convert.ToInt32(Console.ReadLine());
int[] num={input1,input2,input3,input4,input5};
for(i=0;i<5;i++)
int temp=num[i];
int maxf=0;
while(temp!=0)
int r = temp%10;
freq[r]++;
temp/=10;
if(freq[r]>maxf)
maxf=freq[r];
for(j=0;j<10;j++)
if(j==10)
Stable[stable]=num[i];
stable++;
else
Unstable[unstable]=num[i];
unstable++;
Array.Sort(Stable);
Array.Sort(Unstable);
int maxstable=Stable[4];
int minunstable=Unstable[unstable+1];
int sum=maxstable+minunstable;
Console.WriteLine(sum);
/*for(int l=0;l<5;l++)
Console.WriteLine(Stable[l]);
*/
we see that there are THREE stable numbers 12,1313 and 678
So, the password should be=sum of all stable numbers – sum of all Unstable numbers=983
using System;
//the Password should be=Sum of all stable numbers - Sum of all Unstable
//input=12,1313,122,678,898
//result=983
int input1=Convert.ToInt32(Console.ReadLine());
int input2=Convert.ToInt32(Console.ReadLine());
int input3=Convert.ToInt32(Console.ReadLine());
int input4=Convert.ToInt32(Console.ReadLine());
int input5=Convert.ToInt32(Console.ReadLine());
int[] num={input1,input2,input3,input4,input5};
int sums=0;
int sumu=0;
for(i=0;i<5;i++)
int temp=num[i];
int maxf=0;
while(temp!=0)
int r = temp%10;
freq[r]++;
temp/=10;
if(freq[r]>maxf)
maxf=freq[r];
for(j=0;j<10;j++)
break;
}
if(j==10)
stable++;
sums=sums+num[i];
else
unstable++;
sumu=sumu+num[i];
Console.WriteLine(sums-sumu);
we see that there are THREE stable numbers 12,1313 and 678 and
So, the Password should be=Maximum of all stable numbers - Minimum of all Unstable numbers=1313-122=1191
using System;
//12,1313,122,678,898 result=1191
int input1=Convert.ToInt32(Console.ReadLine());
int input2=Convert.ToInt32(Console.ReadLine());
int input3=Convert.ToInt32(Console.ReadLine());
int input4=Convert.ToInt32(Console.ReadLine());
int input5=Convert.ToInt32(Console.ReadLine());
int[] num={input1,input2,input3,input4,input5};
for(i=0;i<5;i++)
int temp=num[i];
int maxf=0;
while(temp!=0)
int r = temp%10;
freq[r]++;
temp/=10;
if(freq[r]>maxf)
maxf=freq[r];
for(j=0;j<10;j++)
break;
if(j==10)
Stable[stable]=num[i];
stable++;
else
Unstable[unstable]=num[i];
unstable++;
}
Array.Sort(Stable);
Array.Sort(Unstable);
int maxstable=Stable[4];
int minunstable=Unstable[unstable+1];
Console.WriteLine((maxstable-minunstable));
/*for(int l=0;l<5;l++)
Console.WriteLine(Stable[l]);
*/
we see that there are THREE stable numbers 12,1313 and 678
So, the Password should be=Maximum of all Unstable numbers - Minimum of all Unstable numbers=898-122=776
using System;
//12,1313,122,678,898
//Result=(numbers=898-122=776)
int input1=Convert.ToInt32(Console.ReadLine());
int input2=Convert.ToInt32(Console.ReadLine());
int input3=Convert.ToInt32(Console.ReadLine());
int input4=Convert.ToInt32(Console.ReadLine());
int input5=Convert.ToInt32(Console.ReadLine());
int[] num={input1,input2,input3,input4,input5};
int[] Stable=new int[5];
for(i=0;i<5;i++)
int temp=num[i];
int maxf=0;
while(temp!=0)
int r = temp%10;
freq[r]++;
temp/=10;
if(freq[r]>maxf)
maxf=freq[r];
for(j=0;j<10;j++)
break;
if(j==10)
Stable[stable]=num[i];
stable++;
else
Unstable[unstable]=num[i];
unstable++;
Array.Sort(Unstable);
int maxunstable=Unstable[4];
int minunstable=Unstable[unstable+1];
int result=maxunstable-minunstable;
Console.WriteLine(result);
we see that there are THREE stable numbers 12,1313 and 678
using System;
//12,1313,122,678,898
//Result=(numbers=898-122=1020)
int input1=Convert.ToInt32(Console.ReadLine());
int input2=Convert.ToInt32(Console.ReadLine());
int input3=Convert.ToInt32(Console.ReadLine());
int input4=Convert.ToInt32(Console.ReadLine());
int input5=Convert.ToInt32(Console.ReadLine());
int[] num={input1,input2,input3,input4,input5};
int sum=0;
for(i=0;i<5;i++)
int temp=num[i];
int maxf=0;
while(temp!=0)
int r = temp%10;
freq[r]++;
temp/=10;
if(freq[r]>maxf)
maxf=freq[r];
for(j=0;j<10;j++)
break;
if(j==10)
stable++;
else
sum=sum+num[i];
unstable++;
Console.WriteLine(sum);
we see that there are THREE stable numbers 12,1313 and 678
So, the Password should be=Maximum of all stable numbers + Minimum of all stable numbers=1313 + 12=1325
using System;
//12,1313,122,678,898
//Result=1313-12=1325
int input1=Convert.ToInt32(Console.ReadLine());
int input2=Convert.ToInt32(Console.ReadLine());
int input3=Convert.ToInt32(Console.ReadLine());
int input4=Convert.ToInt32(Console.ReadLine());
int input5=Convert.ToInt32(Console.ReadLine());
int[] num={input1,input2,input3,input4,input5};
for(i=0;i<5;i++)
int temp=num[i];
int maxf=0;
while(temp!=0)
int r = temp%10;
freq[r]++;
temp/=10;
if(freq[r]>maxf)
maxf=freq[r];
for(j=0;j<10;j++)
break;
}
if(j==10)
Stable[stable]=num[i];
stable++;
else
unstable++;
Array.Sort(Stable);
int maxstable=Stable[4];
int minstable=Stable[stable-1];
int result=maxstable+minstable;
Console.WriteLine(result);
Example 1: Input1 = 10
Input2 = {“Rajesh", “ Abdul", “Rahul”, “Priya”, “Sanjay", "Nidhi”, “Varun”, “Varsha”, “Basil”, “Asif”}
Input3 = {99, 46, 39, 102, 45, 521, 65, 4, 47, 741}
Example 2:
Input1= 7
Inpul 3={9,89,5,0,6,65,4}
using System;
//Input1= 7
//Inpul 3={9,89,5,0,6,65,4}
//Expected output = "ee:cc:gg"
//Input1 = 10
//Input2 = {“Rajesh", “ Abdul", “Rahul”, “Priya”, “Sanjay", "Nidhi”, “Varun”, “Varsha”, “Basil”, “Asif”}
//Input3 = {99, 46, 39, 102, 45, 521, 65, 4, 47, 741}
int input1=Int32.Parse(Console.ReadLine());
string[] input2=new
string[]{"Rajesh","Abdul","Rahul","Priya","Sanjay","Nidhi","Varun","Varsha","Basil","Asif"};
int[] input3={99, 46, 39, 102, 45, 521, 65, 4, 47, 741};
int i,x=0,y=0,z=0,flag=0;
for(int m=0;m<input1;m++)
a[m]=input3[m];
Array.Sort(a);
for(i=0;i<input1-2;i++)
flag=1;
x=a[i+2];
y=a[i+1];
z=a[i];
break;
if(flag==0)
{
Console.WriteLine("NONE");
int fi=0,si=0,ti=0;
for(i=0;i<input1;i++)
if(x==input3[i])
{fi=i;}
if(y==input3[i])
{si=i;}
if(z==input3[i])
{ ti=i;}
Console.Write(input2[fi]+":"+input2[si]+":"+input2[ti]);
Example 1: Input1 = 10
Input3 = {99,46,39,102,45,521,65,4,47,741}
Example 2:
Input1= 17
Input3 = {9,89,5,0,6,65,4}
Example 3:
Input1 = 4
Input3 = {9,76,8,23}
using System;
//Input1= 7
//Inpul 3={9,89,5,0,6,65,4}
//Input1 = 10
//Input2 = {“Rajesh", “ Abdul", “Rahul”, “Priya”, “Sanjay", "Nidhi”, “Varun”, “Varsha”, “Basil”, “Asif”}
//Input3 = {99, 46, 39, 102, 45, 521, 65, 4, 47, 741}
int input1=Int32.Parse(Console.ReadLine());
string[] input2=new
string[]{"Rajesh","Abdul","Rahul","Priya","Sanjay","Nidhi","Varun","Varsha","Basil","Asif"};
int[] input3={99, 46, 39, 102, 45, 521, 65, 4, 47, 741};
int i,x=0,y=0,z=0,flag=0;
for(int m=0;m<input1;m++)
a[m]=input3[m];
Array.Sort(a);
for(i=0;i<input1-2;i++)
flag=1;
x=a[i];
y=a[i+1];
z=a[i+2];
break;
}
if(flag==0)
Console.WriteLine("NONE");
int fi=0,si=0,ti=0;
for(i=0;i<input1;i++)
if(x==input3[i])
{fi=i;}
if(y==input3[i])
{si=i;}
if(z==input3[i])
{ ti=i;}
Console.Write(input2[fi]+":"+input2[si]+":"+input2[ti]);
PIN = 560037
N= 6
Step1 - Length of Last_Name is less than the Length of First_Name, so the Smaler Name is “Roy” and the Longer
Name is “Rajiv”
Step2 - The user id will be = Last Letter of the smaller name +Entre word in the longer name + Digit at position N in
the PIN when traversing the PIN from left to right +Digit at position N in the PIN when traversing the PIN from
right to left
=Last Letter of “Roy”+ Entre word in Rajiv+ 6th Digit of Pin from left + 6th Digit of PIN from right
=y+ Rajiv+7+5
Therefore, user-id=yRajiv75
using System;
/*Rajiv
Roy
560037
YrAJIV75
*/
string input1=Console.ReadLine();
string input2=Console.ReadLine();
string input3=Console.ReadLine();
string input4=Console.ReadLine();
int s1=input1.Length;
int s2=input2.Length;
String longer="";
String smaller="";
String output1="";
if(s1==s2)
if(input1.CompareTo(input2)>0)
longer=input1;
smaller=input2;
else
longer=input2;
smaller=input1;
}
}
if(s1>s2)
longer=input1;
smaller=input2;
else if(s1<s2)
longer=input2;
smaller=input1;
String pin=input3+"";
String output=smaller[(smaller.Length-1)]+longer+pin[(Int32.Parse(input4)-1)]+pin[(pin.Length-
Int32.Parse(input4))];
for(int i=0;i<output.Length;i++)
if(Char.IsLower(output[i]))
output1+=Char.ToUpper(output[i]);
else
output1+=Char.ToLower(output[i]);
Console.WriteLine(output1);
Example-1 –
PIN = 560037
N=6
Step1 - Length of Last Name is less than the Length of First Name, so the Smaller Name is "Roy and the Longer Name
is "Rajiv“ Step2 - The user-id will be
= Last Letter of the longer name + Entire word of the smaller name + Digit at position N in the PIN when traversing
the PIN from left to right + Digit at position N in the PIN when traversing the PIN from right to left
= Last Letter of “Rajiv” + Entire word of “Roy” + 6th Digit of pin from left + 6th Digit of pin from right
= v + Roy + 7 + 5
using System;
/*
Rajiv
Roy
560037
VrOY75
*/
string input1=Console.ReadLine();
string input2=Console.ReadLine();
string input3=Console.ReadLine();
string input4=Console.ReadLine();
int s1=input1.Length;
int s2=input2.Length;
String longer="";
String smaller="";
String output1="";
if(s1==s2)
if(input1.CompareTo(input2)>0)
{
longer=input1;
smaller=input2;
else
longer=input2;
smaller=input1;
if(s1>s2)
longer=input1;
smaller=input2;
else if(s1<s2)
longer=input2;
smaller=input1;
String pin=input3+"";
String output=Convert.ToString(longer[longer.Length-1])+smaller+pin[(Int32.Parse(input4)-
1)]+pin[(pin.Length-Int32.Parse(input4))];
for(int i=0;i<output.Length;i++)
if(Char.IsLower(output[i]))
output1+=Char.ToUpper(output[i]);
else
output1+=Char.ToLower(output[i]);
}
}
Console.WriteLine(output1);
Anand was assigned the task of coming up with an encoding mechanism for any given three strings. He has come
up with the following plan. Step ONE: Given any three strings, break each string into 3 parts each. For example- if
the three strings are below:
Input 1: “John”
Input 2: “Johny”
Input 3: “Janardhan”
“John” should be split into “J”, “oh”, “n,” as the FRONT, MIDDLE and END part, respectively.
“Johny” should be split into “Jo”, “h”, “ny” as the FRONT, MIDDLE and END, respectively.
“Janardhan” should be split into “Jan”, “ard”, “han” as the FRONT, MIDDLE and END part, respectively.
Step TWO:
Concatenate (join) the FRONT, MIDDLE and END parts of the string as per the below specified concatenation –
rule to from three Output strings.
Output1: FRONT part of input 1 + FRONT part of input 2 + FRONT part of input 3
Output2: MIDDLE part of input1 + MIDDLE part of input2 + MIDDLE part of input3
Output3: END part of the input1 + END part of input2 + END part of input3
Step THREE: Process the resulting output strings based on the output-processing rule. After the above two steps, we
will now have three output strings. Further processing is required only for the third output string as per below rule-
“Toggle the case of each character in the string”, i.e., in the third output string, all lower-case characters should be
made upper-case and vice versa.
Final Result – The three output strings after applying the above three steps i.e.
Output1 = “JJoJan”
Output2= “ohhard’
Output3 = “NNYHAN” Help Anand to write a program that would do the above.
using System;
string input1=Console.ReadLine();
string input2=Console.ReadLine();
string input3=Console.ReadLine();
String frnt1="",mid1="",end1="";
String frnt2="",mid2="",end2="";
String frnt3="",mid3="",end3="";
String output1="",output2="",output3="";
int len1=input1.Length;
int len2=input2.Length;
int len3=input3.Length;
if(len1==input1.Length){
if(len1%3==0)
frnt1=input1.Substring(0, (len1/3));
mid1=input1.Substring((len1/3), (len1/3));
end1=input1.Substring(2*(len1/3));
else if((len1-1)%3==0)
frnt1=input1.Substring(0, (len1/3));
mid1=input1.Substring((len1/3), ((len1/3)+1));
end1=input1.Substring(((2*(len1/3))+1));
else if((len1-2)%3==0)
frnt1=input1.Substring(0, ((len1/3)+1));
mid1=input1.Substring(((len1/3)+1), (len1/3));
end1=input1.Substring(((2*(len1/3))+1));
}
if(len2==input2.Length){
if(len2%3==0)
frnt2=input2.Substring(0, (len2/3));
mid2=input2.Substring((len2/3), (len2/3));
end2=input2.Substring(2*(len2/3));
else if((len2-1)%3==0)
frnt2=input2.Substring(0, (len2/3));
mid2=input2.Substring((len2/3), (len2/3+1));
end2=input2.Substring(((2*(len2/3))+1));
else if((len2-2)%3==0)
frnt2=input2.Substring(0, ((len2/3)+1));
mid2=input2.Substring(((len2/3)+1), (len2/3));
end2=input2.Substring(((2*(len2/3))+1));
if(len3==input3.Length){
if(len3%3==0)
frnt3=input3.Substring(0, (len3/3));
mid3=input3.Substring((len3/3), (len3/3));
end3=input3.Substring(2*(len3/3));
else if((len3-1)%3==0)
frnt3=input3.Substring(0, (len3/3));
mid3=input3.Substring((len3/3), (len3/3+1));
end3=input3.Substring(((2*(len3/3))+1));
}
else if((len3-2)%3==0)
frnt3=input3.Substring(0, ((len3/3)+1));
mid3=input3.Substring(((len3/3)+1), (len3/3));
end3=input3.Substring(((2*(len3/3))+1));
output1=frnt1+frnt2+frnt3;
output2=mid1+mid2+mid3;
output3=end1+end2+end3;
int l=output3.Length;
for(int i=0;i<l;i++)
if(Char.IsUpper(output3[i]))
arr[i]=Char.ToLower(output3[i]);
else
arr[i]=Char.ToUpper(output3[i]);
Console.WriteLine(output1);
Console.WriteLine(output2);
Console.WriteLine(str);
Step ONE: Given any three strings, break each string into 3 parts each. For example- if the three strings are below:
Input 1: “John”
Input 2: “Johny”
Input 3: “Janardhan”
“John” should be split into “J”, “oh”, “n,” as the FRONT, MIDDLE and END part, respectively.
“Johny” should be split into “Jo”, “h”, “ny” as the FRONT, MIDDLE and END, respectively.
“Janardhan” should be split into “Jan”, “ard”, “han” as the FRONT, MIDDLE and END part, respectively.
Step TWO: Concatenate (join) the FRONT, MIDDLE and END parts of the string as per the below specified
concatenation – rule to from three Output strings.
Output1: FRONT part of input 1 + MIDDLE part of input 2 + END part of input 3
Output2: MIDDLE part of input1 + END part of input2 + FRONT part of input3
Output3: END part of the input1 + FRONT part of input2 + MIDDLE part of input3
Final Result – The three output strings after applying the above three steps i.e. for the above example.
Output1 = “Jnhan”
Output2= “ohnyJan’
Output3 = “NjOARD”
using System;
string input1=Console.ReadLine();
string input2=Console.ReadLine();
string input3=Console.ReadLine();
String frnt1="",mid1="",end1="";
String frnt2="",mid2="",end2="";
String frnt3="",mid3="",end3="";
String output1="",output2="",output3="";
int len1=input1.Length;
int len2=input2.Length;
int len3=input3.Length;
if(len1==input1.Length){
if(len1%3==0)
frnt1=input1.Substring(0, (len1/3));
mid1=input1.Substring((len1/3), (len1/3));
end1=input1.Substring(2*(len1/3));
else if((len1-1)%3==0)
frnt1=input1.Substring(0, (len1/3));
mid1=input1.Substring((len1/3), ((len1/3)+1));
end1=input1.Substring(((2*(len1/3))+1));
else if((len1-2)%3==0)
frnt1=input1.Substring(0, ((len1/3)+1));
mid1=input1.Substring(((len1/3)+1), (len1/3));
end1=input1.Substring(((2*(len1/3))+1));
if(len2==input2.Length){
if(len2%3==0)
frnt2=input2.Substring(0, (len2/3));
mid2=input2.Substring((len2/3), (len2/3));
end2=input2.Substring(2*(len2/3));
else if((len2-1)%3==0)
frnt2=input2.Substring(0, (len2/3));
mid2=input2.Substring((len2/3), (len2/3+1));
end2=input2.Substring(((2*(len2/3))+1));
}
else if((len2-2)%3==0)
frnt2=input2.Substring(0, ((len2/3)+1));
mid2=input2.Substring(((len2/3)+1), (len2/3));
end2=input2.Substring(((2*(len2/3))+1));
if(len3==input3.Length){
if(len3%3==0)
frnt3=input3.Substring(0, (len3/3));
mid3=input3.Substring((len3/3), (len3/3));
end3=input3.Substring(2*(len3/3));
else if((len3-1)%3==0)
frnt3=input3.Substring(0, (len3/3));
mid3=input3.Substring((len3/3), (len3/3+1));
end3=input3.Substring(((2*(len3/3))+1));
else if((len3-2)%3==0)
frnt3=input3.Substring(0, ((len3/3)+1));
mid3=input3.Substring(((len3/3)+1), (len3/3));
end3=input3.Substring(((2*(len3/3))+1));
output1=frnt1+mid2+end3;
output2=mid1+end2+frnt3;
output3=end1+frnt2+mid3;
int l=output3.Length;
for(int i=0;i<l;i++)
{
if(Char.IsUpper(output3[i]))
arr[i]=Char.ToLower(output3[i]);
else
arr[i]=Char.ToUpper(output3[i]);
Console.WriteLine(output1);
Console.WriteLine(output2);
Console.WriteLine(str);
Step ONE: Given any three strings, break each string into 3 parts each. For example- if the three strings are below:
Input 1: “John”
Input 2: “Johny”
Input 3: “Janardhan”
“John” should be split into “J”, “oh”, “n,” as the FRONT, MIDDLE and END part,
respectively. “Johny” should be split into “Jo”, “h”, “ny” as the FRONT, MIDDLE and END, respectively.
“Janardhan” should be split into “Jan”, “ard”, “han” as the FRONT, MIDDLE and END part, respectively.
Step TWO: Concatenate (join) the FRONT, MIDDLE and END parts of the string as per the below specified
concatenation – rule to from three Output strings.
Output1: FRONT part of input 1 + END part of input 2 + MIDDLE part of input 3
Output2: MIDDLE part of input1 + FRONT part of input2 + END part of input3
Output3: END part of the input1 + MIDDLE part of input2 + FRONT part of input3
Final Result – The three output strings after applying the above three steps i.e.
Output2= “ohJohan’
Output3 = “NHjAN”
using System;
string input1=Console.ReadLine();
string input2=Console.ReadLine();
string input3=Console.ReadLine();
String frnt1="",mid1="",end1="";
String frnt2="",mid2="",end2="";
String frnt3="",mid3="",end3="";
String output1="",output2="",output3="";
int len1=input1.Length;
int len2=input2.Length;
int len3=input3.Length;
if(len1==input1.Length){
if(len1%3==0)
frnt1=input1.Substring(0, (len1/3));
mid1=input1.Substring((len1/3), (len1/3));
end1=input1.Substring(2*(len1/3));
else if((len1-1)%3==0)
frnt1=input1.Substring(0, (len1/3));
mid1=input1.Substring((len1/3), ((len1/3)+1));
end1=input1.Substring(((2*(len1/3))+1));
else if((len1-2)%3==0)
{
frnt1=input1.Substring(0, ((len1/3)+1));
mid1=input1.Substring(((len1/3)+1), (len1/3));
end1=input1.Substring(((2*(len1/3))+1));
if(len2==input2.Length){
if(len2%3==0)
frnt2=input2.Substring(0, (len2/3));
mid2=input2.Substring((len2/3), (len2/3));
end2=input2.Substring(2*(len2/3));
else if((len2-1)%3==0)
frnt2=input2.Substring(0, (len2/3));
mid2=input2.Substring((len2/3), (len2/3+1));
end2=input2.Substring(((2*(len2/3))+1));
else if((len2-2)%3==0)
frnt2=input2.Substring(0, ((len2/3)+1));
mid2=input2.Substring(((len2/3)+1), (len2/3));
end2=input2.Substring(((2*(len2/3))+1));
if(len3==input3.Length){
if(len3%3==0)
frnt3=input3.Substring(0, (len3/3));
mid3=input3.Substring((len3/3), (len3/3));
end3=input3.Substring(2*(len3/3));
else if((len3-1)%3==0)
{
frnt3=input3.Substring(0, (len3/3));
mid3=input3.Substring((len3/3), (len3/3+1));
end3=input3.Substring(((2*(len3/3))+1));
else if((len3-2)%3==0)
frnt3=input3.Substring(0, ((len3/3)+1));
mid3=input3.Substring(((len3/3)+1), (len3/3));
end3=input3.Substring(((2*(len3/3))+1));
output1=frnt1+end2+mid3;
output2=mid1+frnt2+end3;
output3=end1+mid2+frnt3;
int l=output3.Length;
for(int i=0;i<l;i++)
if(Char.IsUpper(output3[i]))
arr[i]=Char.ToLower(output3[i]);
else
arr[i]=Char.ToUpper(output3[i]);
Console.WriteLine(output1);
Console.WriteLine(output2);
Console.WriteLine(str);
Input 1: “John”
Input 2: “Johny”
Input 3: “Janardhan”
“John” should be split into “J”, “oh”, “n,” as the FRONT, MIDDLE and END part, respectively.
“Johny” should be split into “J”, “ohn”, “y” as the FRONT, MIDDLE and END, respectively.
“Janardhan” should be split into “Jan”, “ard”, “han” as the FRONT, MIDDLE and END part, respectively.
Step TWO: Concatenate (join) the FRONT, MIDDLE and END parts of the string as per the below specified
concatenation – rule to from three Output strings.
Output1: FRONT part of input 1 + MIDDLE part of input 2 + END part of input 3
Output2: MIDDLE part of input1 + END part of input2 + FRONT part of input3
Output3: END part of the input1 + FRONT part of input2 + MIDDLE part of input3
Final Result – The three output strings after applying the above three steps i.e. for the above example.
Output1 = “Johnhan”
Output2= “ohyJan’
Output3 = “NjARD”
using System;
string input1=Console.ReadLine();
string input2=Console.ReadLine();
string input3=Console.ReadLine();
String frnt1="",mid1="",end1="";
String frnt2="",mid2="",end2="";
String frnt3="",mid3="",end3="";
String output1="",output2="",output3="";
int len1=input1.Length;
int len2=input2.Length;
int len3=input3.Length;
if(len1==input1.Length){
if(len1%3==0)
frnt1=input1.Substring(0, (len1/3));
mid1=input1.Substring((len1/3), (len1/3));
end1=input1.Substring(2*(len1/3));
else if((len1-1)%3==0)
frnt1=input1.Substring(0, (len1/3));
mid1=input1.Substring((len1/3), ((len1/3)+1));
end1=input1.Substring(((2*(len1/3))+1));
else if((len1-2)%3==0)
frnt1=input1.Substring(0, ((len1/3)+1));
mid1=input1.Substring(((len1/3)+1), (len1/3));
end1=input1.Substring(((2*(len1/3))+1));
if(len2==input2.Length){
if(len2%3==0)
frnt2=input2.Substring(0, (len2/3));
mid2=input2.Substring((len2/3), (len2/3));
end2=input2.Substring(2*(len2/3));
else if((len2-1)%3==0)
frnt2=input2.Substring(0, (len2/3));
mid2=input2.Substring((len2/3), (len2/3+1));
end2=input2.Substring(((2*(len2/3))+1));
else if((len2-2)%3==0)
frnt2=input2.Substring(0, (len2/3));
mid2=input2.Substring((len2/3), (len2/3+len2%3));
end2=input2.Substring(((2*(len2/3))+1));
if(len3==input3.Length){
if(len3%3==0)
frnt3=input3.Substring(0, (len3/3));
mid3=input3.Substring((len3/3), (len3/3));
end3=input3.Substring(2*(len3/3));
else if((len3-1)%3==0)
frnt3=input3.Substring(0, (len3/3));
mid3=input3.Substring((len3/3), (len3/3+1));
end3=input3.Substring(((2*(len3/3))+1));
else if((len3-2)%3==0)
frnt3=input3.Substring(0, ((len3/3)+1));
mid3=input3.Substring(((len3/3)+1), (len3/3));
end3=input3.Substring(((2*(len3/3))+1));
output1=frnt1+mid2+end3;
output2=mid1+end2+frnt3;
output3=end1+frnt2+mid3;
int l=output3.Length;
if(Char.IsUpper(output3[i]))
arr[i]=Char.ToLower(output3[i]);
else
arr[i]=Char.ToUpper(output3[i]);
Console.WriteLine(output1);
Console.WriteLine(output2);
Console.WriteLine(str);
NOTE 1: if all the characters in the word are already sufficient to form a palindrome, then the number of characters
that have to be removed from the word should be 0.
NOTE 2: if all the characters in the word are different and cannot form a palindrome, then the number of characters
that have to be removed from the word should be -1
NOTE 3: Ignore the case of the letters white doing the check
i.e "Template” or “template" or “TEMplate” or “TEmPLAte” or “TEMPLATE” should all give the same result which is 3
NOTE 4: You can assume that the given word will be a single word with no spaces and only alphabet characters.
using System;
String input1=Console.ReadLine();
input1=input1.ToLower();
for(int i=0;i<input1.Length;i++)
h[(int)input1[i]-97]++;
int c=0;
for(int i=0;i<26;i++)
if(h[i]%2==1)
c++;
if(c==0 || c==1)
Console.WriteLine(0);
else if(c==input1.Length)
Console.WriteLine(-1);
else
Console.WriteLine(c-1);
Example1 –
= 370
Example2 –
= 1 + 13 + 45 + 97
= 156
using System;
int r=Int32.Parse(Console.ReadLine());
int a=Int32.Parse(Console.ReadLine());
int k=Int32.Parse(Console.ReadLine());
int j=2,s=a;
for(int i=1;i<r;i++)
s+=(a*i)+(a+k)*j;
j+=1;
a+=k;
Console.WriteLine(s);
JUMBLED WORD
Example1:
Example2:
input2=2
input2=1
Example4:
input1="WIPRO LIMITED"
input2=2
using System;
int input2=Int32.Parse(Console.ReadLine());
string s1="",res="",even="",odd="";
for(int i=0;i<s.Length;i++)
s1=s[i];
even="";
odd="";
for(int j=0;j<s1.Length;j++)
if(j%2==0)
even+=s1[j];
}
else
odd+=s1[j];
if(input2==1)
char[] arr=odd.ToCharArray();
Array.Reverse(arr);
res+=even+sk+" ";
else
res+=even+odd+" ";
Console.WriteLine(res);
Sample Input/Output-1
Input1= we8+you2-7to/*32
Output=2
Explanation: Here the operators are [+,-,/,*] and the numbers are [8,2,7,3,2] Thus we would be getting 8+2=>10-
7=>3/3=>1*2=>2
Final answer is 2.
Sample Input/Output-2
Input1= i*-t5s-t8h1e4birds
Output=35
Explanation: Here the operators are [+,-,-] and the numbers are [5,8,1,4] Thus we would be getting 5*8=>40-1=>39-
4=>35
string input1=Console.ReadLine();
int len=input1.Length;
int k1=0,k2=0;
for(int i=0;i<len;i++)
if(!Char.IsLetter(input1[i]))
if(Char.IsDigit(input1[i]))
d[k1++]=Int32.Parse(Convert.ToString(input1[i]));
else
c[k2++]=input1[i];
int res=d[0],k=1;
for(int i=0;i<k2;i++)
if(c[i]=='+')
res+=d[k];
else if(c[i]=='-')
{
res-=d[k];
else if(c[i]=='*')
res*=d[k];
else
res/=d[k];
k++;
Console.WriteLine(res);
Example-1
Input1 = ww:ii:pp:rr:oo
Word5 is oo,
Example-2
Input1= zx:za:ee
Output=BYE
using System;
{
public static void Main()
string input1=Console.ReadLine();
String[] s=input1.Split(':');
String s1="",res="";
int x,len=s.Length;
for(int i=0;i<len;i++)
s1=s[i];
if(((int)s1[0])-((int)s1[1])==0)
res+=s1[0];
else if(((int)s1[0])-((int)s1[1])>0)
x=((int)s1[0])-((int)s1[1]);
res+=((char)(96+x));
else
x=((int)s1[1])-((int)s1[0]);
res+=((char)(96+x));
Console.WriteLine(res.ToUpper());
its RSF can be found by concatenating the difference between (6 and 9), (9 and 2) and (2 and 8) as shown below –
Difference between 6 and 9 is 3
The resultant RSF (376) is not a two-digit number, so we must continue finding its “Reduced Subtracted Form(RSF)”
The resultant RSF (41) is two-digit number, so we have reached the “two-digit Reduced Subtracted Form”.
If input1 = 5271
Expected output = 21
RSF of 356=(3-5)(5-6)=21
using System;
int input1=Int32.Parse(Console.ReadLine());
while(input1>=100)
int x=input1,l=0;
while(input1>0)
input1=input1/10;
l++;
int i=l-1;
while(x>0)
a[i]=x%10;
x=x/10;
i--;
}
for(int j=0;j<l-1;j++)
input1=input1*10+Math.Abs(a[j]-a[j+1]);
Console.WriteLine(input1);
Example 1:
Example 2:
using System;
int input3=Int32.Parse(Console.ReadLine());
for(int a=0;a<input3;a++)
input1[a]=Console.ReadLine();
for(int a=0;a<input3;a++)
{
input2[a]=Console.ReadLine();
String res="";
for(int i=0;i<input3;i++)
char[] t1 = input1[i].ToCharArray();
char[] t2 = input2[i].ToCharArray();
//sorting
Array.Sort(t1);
Array.Sort(t2);
for(int i=0;i<input3;i++)
for(int j=0;j<input3;j++)
if(input1[i].Equals(input2[j]))
res=res+j;
break;
Console.WriteLine(Int32.Parse(res));
using System;
int input1=Int32.Parse(Console.ReadLine());
while(input1>=10)
int x=input1,l=0;
while(input1>0)
input1=input1/10;
l++;
int i=l-1;
while(x>0)
a[i]=x%10;
x=x/10;
i--;
for(int j=0;j<l-1;j++)
input1=input1*10+Math.Abs(a[j]-a[j+1]);
Console.WriteLine(input1);
Input2=41
Output=cein daydoT
using System;
using System.Text;
string input1=Console.ReadLine();
int input2=Int32.Parse(Console.ReadLine());
int nu1=input2/10;
int nu2=input2%10;
string s1=s[nu1-1];
char[] arr=s1.ToCharArray();
Array.Reverse(arr);
string s2=s[nu2-1];
char[] arr1=s2.ToCharArray();
Array.Reverse(arr1);
int l1=s1.Length;
int l2=s2.Length;
string r1=s1.Substring(l1/2)+sr1.Substring(l1/2);
string r2=s2.Substring(l2/2)+sr2.Substring(l2/2);
Console.WriteLine(r1+" "+r2);
using System;
//1,3,6,8,11,13,16,18,21,23,,26,28,31,33,36,38,41
int input1=Int32.Parse(Console.ReadLine());
int input2=Int32.Parse(Console.ReadLine());
int input3=Int32.Parse(Console.ReadLine());
int input4=Int32.Parse(Console.ReadLine());
if (i % 2 == 1)
output += gap1;
else
output += gap2;
Console.WriteLine(output);
EATRY JOINT
using System;
int[,] input1={{0,2},{2,3},{2,2},{5,2}};
int input2=Int32.Parse(Console.ReadLine());
int time=input1[0,1];
String se="c0-";
int count=1;
String le="";
for(int i=1;i<input2;i++)
if(time<=input1[i,0])
time=time+input1[i,1];
se=se+"c"+i+"-";
count++;
else
le=le+"c"+i+"-";
String ans="";
if(count==input2)
ans="served";
else
se=se.Substring(0,se.Length-1);
if(le.Length>0)
le=le.Substring(0,le.Length-1);
ans=se+":"+le;
Console.WriteLine(ans);
using System;
static String[] word = {"zero", "one", "two", "three","four", "five", "six", "seven","eight","nine"};
int input1=Int32.Parse(Console.ReadLine());
int num=1,count=0,j;
while(count<input1)
num=num+1;
for(j=2;j<=num;j++)
if(num%j==0)
break;
if(j==num)
count++;
int n=num;
String s="",w="";
int dc = 0;
do
digits[dc] = n % 10;
n = n/10;
dc++;
} while (n != 0);
if(Char.IsLetter(s[i])){
w += s[i];
}
w=w+w.Length;
Console.WriteLine(w);
Example1:
input1= "Fi_er”
input2=”Fever:filer:Filter: Fixer:fiber:fibre:tailor:offer”
using System;
string input1=Console.ReadLine();
string input2=Console.ReadLine();
input1=input1.ToUpper();
input2=input2.ToUpper();
int i,j;
for(i=0;i<words.Length;i++)
word = words[i];
if(input1.Length==word.Length)
for(j=0;j<input1.Length;j++)
if((input1[j]!='_')&&(input1[j]!=word[j]))
break;
}
}
if(j==input1.Length)
res=res + word+":";
Console.WriteLine(res.Length==0?"ERROR-009":res.Substring(0,res.Length-1));
Given a number N (1<=N<=10000), and an option opt=1 or 2, find the result as per below rules,
Result =6+5-4+3-2+1= 9
using System;
int N=Int32.Parse(Console.ReadLine());
int opt=Int32.Parse(Console.ReadLine());
int sum=0;
sum+=N;
N=N-1;
if(opt==2)
if(N%2==0)
while(N>0)
{
if(N%2==0)
sum+=N;
else
sum-=N;
N--;
else
while(N>0)
if(N%2==0)
sum-=N;
else
sum+=N;
N--;
else
if(N%2==0)
while(N>0)
if(N%2==0)
sum-=N;
else
sum+=N;
N--;
else
{
while(N>0)
if(N%2==0)
sum+=N;
else
sum-=N;
N--;
Console.WriteLine(sum);
using System;
//input1={10,5,70,1};
//output cbda
int[] input1={10,5,70,1};
int[] sorted_input=(int[])input1.Clone();
Array.Sort(sorted_input);
foreach(int i in input1)
ind=Array.IndexOf(sorted_input,i);
//Console.WriteLine(ind+1);
result[o]=(char)(ind+1+96);
o++;
}
Console.WriteLine(result);