Irp May 29th
Irp May 29th
IRP 29-05-2022
1)Rajiv and Nitish had a fight because Rajiv was annoying Nitish with his question.
Rajiv being a genius in arrays gave Nitish an array of natural numbers A of length
N with elements A1, A2, . . ., AN. Nitish has to find the total amount of perfect
pairs in the array.
A perfect pair (Ai, Aj) is a pair where (Ai + Aj) is a perfect square or a perfect
cube and i ≠ j.
Since Rajiv and Nitish are not talking with each other after the fight you have
been given the question to solve and inturn make both of them a perfect pair again.
NOTE:- A pair (Ai, Aj) and (Aj, Ai) are the same and not to be counted twice.
CODE :- C
}
}
}
}
printf("%d\n",(count)/2+flag);
}
return 0;
}
s = "snakesandladder",
CODE :- JAVA
import java.util.*;
class DictionaryWord {
3)You’re given a string as an input. You have to reverse the string by keeping the
punctuation and spaces. You have to modify the source string itself by creating
another string.
str1=list(input())
str2=[]
for i in str1:
if i.isalnum():
str2.append(i)
str2=list(str2[::-1])
for i in range(len(str1)):
if str1[i].isalnum()==False:
str2.insert(i,str1[i])
for i in str2:
print(i,end="")
print()
SOLUTION 2 :-
CODE :- JAVA
import java.util.*;
import java.lang.*;
class Main{
public static void main(String args[]){
Scanner s=new Scanner(System.in);
String str=s.nextLine();
char[] input = str.toCharArray();
char[] result=new char[input.length];
for(int i=0;i<input.length;i++){
if(input[i]==' '||input[i]== ','|| input[i] == '.'||input[i] == '!'||
input[i] == '?'||input[i]== ':' ||input[i] == ';'||input[i]=='-')
result[i]=input[i];
}
int k=0;
for(int i=input.length-1;i>=0;i--){
if(input[i]!=' '&&input[i]!= ','&& input[i] != '.'&&input[i] !=
'!'&&input[i] != '?'&&input[i]!= ':' &&input[i] != ';'&&input[i]!='-')
{
if(result[k]=='\0'){
result[k]=input[i];
k++;
}
else {
result[++k]=input[i];
k++;
}
}
}
for(int i=0;i<input.length;i++){
System.out.print(result[i]);
}
}
}