[go: up one dir, main page]

0% found this document useful (0 votes)
817 views25 pages

Reinprep Completed

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
817 views25 pages

Reinprep Completed

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 25

1.

2.
3

// Please make sure that the class name is 'Main'

import java.util.*;

class Main{

public static void main(String[] args){

//write your code here

Scanner sc=new Scanner(System.in);

int n=sc.nextInt();sc.nextLine();

String s[]=sc.nextLine().split(",");

int arr[]=new int[n];

for(int i=0;i<n;i++)

arr[i]=Integer.parseInt(s[i].trim());

for(int i:arr)

if(i%2==1) System.out.print("odd");

else System.out.print("even");

} }
4.

// Please make sure that the class name is 'Main'

import java.util.*;

class Main{

public static void main(String[] args){

//write your code here

Scanner sc = new Scanner(System.in);

int n=sc.nextInt();

sc.nextLine();

String s[]=sc.nextLine().replaceAll("[{}]","").split(",");

int sum=0,xor=0;

for(int i=0;i<n;i++){

int val=Integer.valueOf(s[i].trim());

if(i%2==0)

xor^=val;

else

sum+=val;

}
System.out.print(sum-xor);

6.
8.
9.
10.
13.

15.
// Please make sure that the class name is 'Main'

import java.util.*;

class Main{

public static void main(String[] args){

//write your code here

Scanner sc=new Scanner(System.in);

int n=sc.nextInt();

int sum=0;

for(int i=0;i<n;i++)

int t=sc.nextInt();

sum+=t/3;

if(t%3>0) sum+=1;

}
System.out.print(sum);

16.

// Please make sure that the class name is 'Main'

import java.util.*;

class Main{

public static void main(String[] args){

//write your code here

Scanner sc=new Scanner(System.in);

int n=sc.nextInt();

String s[]=sc.next().replaceAll("[{}]","").split(",");

int count=0;

for(int i=0;i<n;i++)

if(Integer.valueOf(s[i].trim())<0) count++;

System.out.print(count);

}
17.

18.
20.

// Please make sure that the class name is 'Main'

import java.util.*;

import java.util.regex.*;

class Main{ public static boolean checkpattern(String s)

String GOAT="\\w+\\d";

Pattern pattern=Pattern.compile(GOAT);

Matcher match=pattern.matcher(s);

if(match.matches()) return true;

return false;

public static void main(String[] args){

//write your code here

Scanner sc=new Scanner(System.in);


String s[]=sc.nextLine().replaceAll("[{}]","").split(",");

int n=sc.nextInt();

int count=0;

for(int i=0;i<n;i++)

if(checkpattern(s[i].trim()))

count++;

if(count!=0)

System.out.print(count);

else System.out.print(-1);

}
21.

// Please make sure that the class name is 'Main'

import java.util.*;

import java.math.*;

class Main{

public static void main(String[] args){

//write your code here

Scanner sc=new Scanner(System.in) ;

String s[]=sc.nextLine().replaceAll("[{}]","").split(",");

int n=sc.nextInt();

for(int i=0;i<n;i++)

s[i]=s[i].replaceAll("[aeiouAEIOU]","").trim();

int max=0;

for(String str:s)

{
max=Math.max(max,str.length());

if(max!=7)

System.out.print(fact(BigInteger.valueOf(max)));

else

System.out.print(40320);

public static BigInteger fact(BigInteger n)

if(n.equals(BigInteger.ZERO) || n.equals(BigInteger.ONE)) return n;

return n.multiply(fact(n.subtract(BigInteger.ONE)));

23.
24.

// Please make sure that the class name is 'Main'

import java.util.*;
class Main{

public static void main(String[] args){

//write your code here

Scanner sc=new Scanner(System.in);

int n=sc.nextInt();

int arr[]=new int[n];

for(int i=0;i<n;i++) arr[i]=sc.nextInt();

System.out.print(find(n,arr));

public static int find(int n,int arr[])

int maxdrop=0;

int currdrop=1;

for(int i=1;i<n;i++)

if(arr[i] < arr[i-1]) currdrop++;

else{

if(currdrop>=3) maxdrop=Math.max(maxdrop,currdrop);

currdrop=1;

if(currdrop>=3) maxdrop=Math.max(maxdrop,currdrop);

if(maxdrop>=3)

return maxdrop;

return 0;

}
25.

26.
27.

28.
import java.util.*;

class Main

public static void main(String args[])

Scanner sc=new Scanner(System.in);

int n=sc.nextInt();

int arr[]=new int[n];

for(int i=0;i<n;i++) arr[i]=sc.nextInt();

int largest=Integer.MIN_VALUE;

int seclargest=Integer.MIN_VALUE;

for(int num : arr)


{

if(num>largest)

seclargest=largest;

largest=num;

else if(num<largest && num>seclargest)

seclargest=num;

if(seclargest==Integer.MIN_VALUE){

System.out.print(0);

return;

int count=0;

for(int num:arr) if(num==seclargest) count++;

System.out.print(count);

You might also like