Untitled
-----------------------------------author:-bhanu_017-------------------------------------------- 1ST QUESTION:-import java.util.*; import java.lang.*; import java.io.*; class Codechef { public static void main (String[] args) throws java.lang.Exception { // your code goes here Scanner sc=new Scanner(System.in); int a=sc.nextInt(); int b=sc.nextInt(); int c=sc.nextInt(); int d=15-a-b-c; System.out.println(d); } } 2ND QUESTION:-import java.util.*; import java.lang.*; import java.io.*; class Codechef { public static void main (String[] args) throws java.lang.Exception { // your code goes here Scanner sc=new Scanner(System.in); int t=sc.nextInt(); while(t-->0) { int a=sc.nextInt(); int b=sc.nextInt(); int c=sc.nextInt(); int m=sc.nextInt(); if(a>=b&&a-b<=m) { System.out.println("YES"); } else if(a>=c&&a-c<=m) { System.out.println("YES"); } else if(b>=a&&b-a<=m) { System.out.println("YES"); } else if(b>=c&&b-c<=m) { System.out.println("YES"); } else if(c>=a&&c-a<=m) { System.out.println("YES"); } else if(c>=b&&c-b<=m) { System.out.println("YES"); } else { System.out.println("NO"); } } } } 3RD QUESTION:- import java.util.*; import java.lang.*; import java.io.*; class Codechef { public static void main (String[] args) throws java.lang.Exception { Scanner sc=new Scanner(System.in); int t=sc.nextInt(); while(t-->0) { int[] players=new int[16]; int[] ans=new int[16]; for(int i=0;i<16;i++) { players[i]=sc.nextInt(); } for(int i=0;i<16;i++) { int curr=players[i]; int count=0; for(int num:players) { if(curr>=num)count++; } if(count>1&&count<4) { ans[i]=1; } else if(count>=4&&count<8)ans[i]=2; else if(count>=8&&count<16)ans[i]=3; else if(count==16)ans[i]=4; else ans[i]=0; } for(int num:ans) { System.out.print(num+" "); } } } } // 7 9 15 // 22 18 16 4 2 20 5 10 4TH QUESTION:- import java.util.*; import java.lang.*; import java.io.*; class Codechef { public static void main (String[] args) throws java.lang.Exception { // your code goes here Scanner sc=new Scanner(System.in); int t=sc.nextInt(); while(t-->0) { int n=sc.nextInt(); for(int i=1;i<=n/2;i++) { System.out.print(n-i+1+" "); System.out.print(i+" "); } if(n%2!=0) { System.out.print(n/2+1+" "); } System.out.println(); } } } 5TH QUESTION:-import java.util.*; import java.lang.*; import java.io.*; class Codechef { public static void main (String[] args) throws java.lang.Exception { Scanner sc=new Scanner(System.in); int t=sc.nextInt(); while(t-->0) { int n=sc.nextInt(); int[] arr=new int[n]; for(int i=0;i<n;i++) { arr[i]=sc.nextInt(); } int[] psum=new int[n]; int[] ssum=new int[n]; psum[0]=0; for(int i=1;i<n;i++) { int extra=arr[i-1]; psum[i]=psum[i-1]+extra; } ssum[n-1]=0; for(int i=n-2;i>=0;i--) { int extra=arr[i+1]; ssum[i]=ssum[i+1]+extra; } int ans=0; for(int i=0;i<n;i++) { if(arr[i]==0) { if(Math.abs(psum[i]-ssum[i])==0)ans+=2; else if(Math.abs(psum[i]-ssum[i])==1)ans+=1; else ans+=0; } } System.out.println(ans); } } } ---------------------------------Thank You------------------------------------------
Leave a Comment