diff --git a/CodeShef/Beginner/AddTwoNumbers.java b/CodeShef/Beginner/AddTwoNumbers.java new file mode 100644 index 0000000..1da106d --- /dev/null +++ b/CodeShef/Beginner/AddTwoNumbers.java @@ -0,0 +1,35 @@ +package Beginner; + +// The first line contains an integer T, the total number of test cases. Then follow T lines, each line contains two Integers A and B. +import java.util.*; +class AddTwoNumbers { + public static void main(String[] args) { + Scanner sc = new Scanner(System.in); + int a = sc.nextInt();//Enter number of inputs + int n1 = 0; + int n2 = 0; + + int i = 1; + int j =0; + while (i<=a) { + + while (j<=2) { + n1 = sc.nextInt();//enter first number + n2 = sc.nextInt();//enter second number + System.out.println(n1 + n2); + j++; + } + i++; + } + sc.close(); + + } + } + +// for(int i = 1; i<=a; i++){ + // for(int j = 1; j<=2;j++){ + // n1 = sc.nextInt(); + // n2 = sc.nextInt(); + // System.out.println(n1 + n2); + + // } \ No newline at end of file diff --git a/CodeShef/Easy Problems to Get Started/BuyPlease.java b/CodeShef/Easy Problems to Get Started/BuyPlease.java new file mode 100644 index 0000000..ed799c8 --- /dev/null +++ b/CodeShef/Easy Problems to Get Started/BuyPlease.java @@ -0,0 +1,15 @@ +// Chef went to a shop and buys a pens and b pencils. Each pen costs x units and each pencil costs y units. +// Now find what is the total amount Chef will spend to buy a pens and b pencils. +import java.util.*; +class BuyPlease { + public static void main(String args[]){ + Scanner sc = new Scanner(System.in); + int a = sc.nextInt(); + int b = sc.nextInt(); + int x = sc.nextInt(); + int y = sc.nextInt(); + int sum = a*x + b*y; + System.out.println(sum); + sc.close(); + } +} diff --git a/CodeShef/Easy Problems to Get Started/FactorFinding.java b/CodeShef/Easy Problems to Get Started/FactorFinding.java new file mode 100644 index 0000000..6e41f5c --- /dev/null +++ b/CodeShef/Easy Problems to Get Started/FactorFinding.java @@ -0,0 +1,22 @@ +// You are given a number N and find all the distinct factors of N. +import java.util.*; +class FactorFinding { + public static void main(String args[]){ + Scanner sc = new Scanner(System.in); + int N = sc.nextInt(); // Enter N + int sum = 0; + String factors = ""; + for(int i = 1; i<=N; i++){ + if(N%i == 0){ + sum++; + //System.out.print(i +" "); + factors +=(i + " "); + } + } + // number of factor found + System.out.println(sum); + System.out.println(factors); + sc.close(); + } +} +// completed \ No newline at end of file diff --git a/CodeShef/Easy Problems to Get Started/IsBothOrNot.java b/CodeShef/Easy Problems to Get Started/IsBothOrNot.java new file mode 100644 index 0000000..83d7f21 --- /dev/null +++ b/CodeShef/Easy Problems to Get Started/IsBothOrNot.java @@ -0,0 +1,17 @@ +// You're given a number N. If N is divisible by 5 or 11 but not both then print "ONE"(without quotes). +// If N is divisible by both 5 and 11 then print "BOTH"(without quotes). If N is not divisible by 5 or 11 then print "NONE"(without quotes). +import java.util.*; +class IsBothOrNot { + public static void main(String args[]){ + Scanner sc = new Scanner(System.in); + int N = sc.nextInt(); + if(N%5 == 0 && N%11 == 0){ + System.out.println("BOTH"); + }else if(N%5 == 0 || N % 11 == 0){ + System.out.println("ONE"); + }else{ + System.out.println("NONE"); + } + sc.close(); + } +} diff --git a/CodeShef/Easy Problems to Get Started/addNaturalNumbers.java b/CodeShef/Easy Problems to Get Started/addNaturalNumbers.java new file mode 100644 index 0000000..228aba2 --- /dev/null +++ b/CodeShef/Easy Problems to Get Started/addNaturalNumbers.java @@ -0,0 +1,22 @@ +//You are given a number N. Find the sum of all numbers from 1 to N. +import java.util.*; +class addNaturalNumbers { + public static void main(String[] args) { + + Scanner sc = new Scanner(System.in); + int n = sc.nextInt();//enter n + int a = 0; + int i = 1; + // for(int i = 1; i<=n;i++){ + // a=a+i;//a will be keep on adding until loop ends + // } + // System.out.println(a); + while (i<=n) { + a =a +i; + i = i+1; + } + System.out.println(a); + sc.close(); + } +} +//complete \ No newline at end of file diff --git a/CodeShef/Easy Problems to Get Started/alternativeSquare.java b/CodeShef/Easy Problems to Get Started/alternativeSquare.java new file mode 100644 index 0000000..1246d21 --- /dev/null +++ b/CodeShef/Easy Problems to Get Started/alternativeSquare.java @@ -0,0 +1,33 @@ +// You're given a number N. Print the first N lines of the below-given pattern. + +// 1 2 3 4 5 +// 10 9 8 7 6 +// 11 12 13 14 15 +// 20 19 18 17 16 +// 21 22 23 24 25 +// 30 29 28 27 26 +import java.util.*; +class alternativeSquare { + public static void main(String[] args) { + Scanner sc = new Scanner(System.in); + int n = sc.nextInt(); + int count = 0; + for(int i = 1; i<=n; i++){ + if(i%2 != 0 ){ + for(int j = 1;j<=5; j++){ + count = count + 1; + System.out.print(count + " "); + } + }else { + int temp = count+1; + for(int j = count+5; j>=temp; j--){ + count = count + 1; + System.out.print(j +" "); + } + } + System.out.println(); + } + sc.close(); + } +} +//complete \ No newline at end of file diff --git a/CodeShef/Easy Problems to Get Started/findMe.java b/CodeShef/Easy Problems to Get Started/findMe.java new file mode 100644 index 0000000..f0b7f7b --- /dev/null +++ b/CodeShef/Easy Problems to Get Started/findMe.java @@ -0,0 +1,28 @@ +//You are given a list of N integers and a value K. Print 1 if K exists in the given list of N integers, otherwise print −1. +import java.util.*; +class findMe { + public static void main(String args[]){ + Scanner sc = new Scanner(System.in); + int n = sc.nextInt();// enter size + int k = sc.nextInt();//enter number to find + int integers[] = new int[n]; + String answer = ""; + String notanswer = ""; + for(int i = 0; i=0; i--){ + System.out.print(integers[i] + " "); + } + sc.close(); + } +} +// complete \ No newline at end of file diff --git a/CodeShef/Easy Problems to Get Started/reverseStarPattern.java b/CodeShef/Easy Problems to Get Started/reverseStarPattern.java new file mode 100644 index 0000000..b694b2c --- /dev/null +++ b/CodeShef/Easy Problems to Get Started/reverseStarPattern.java @@ -0,0 +1,24 @@ +// You're given a number N. Print the first N lines of the below-given pattern. + +// * +// ** +// *** +// **** +// ***** +import java.util.*; +class reverseStarPattern { + public static void main(String[] args) { + Scanner sc = new Scanner(System.in); + int n = sc.nextInt(); + for(int i=1; i<=n; i++){ + for(int j = n-i; j>=1; j--){ + System.out.print(" "); + } + for(int j = 1;j<=i;j++){ + System.out.print("*"); + } + System.out.println(); + } + sc.close(); + } +} diff --git a/CodeShef/Easy Problems to Get Started/secondLargest.java b/CodeShef/Easy Problems to Get Started/secondLargest.java new file mode 100644 index 0000000..5ea9268 --- /dev/null +++ b/CodeShef/Easy Problems to Get Started/secondLargest.java @@ -0,0 +1,24 @@ +// Given three distinct integers A, B and C, print the second largest number among them. +import java.util.*; +class secondLargest { + public static void main(String args[]){ + Scanner sc = new Scanner(System.in); + int a = sc.nextInt(); + int b = sc.nextInt(); + int c = sc.nextInt(); + if(a>b && b>c){// a=3 b=2 c=1 + System.out.println(b); + }else if(c>b && b>a){ // a=1 b=2 c=3 + System.out.println(b); + }else if(a>c && c>b){ // a= 3 b=1 c= 2 + System.out.println(c); + }else if(b>c && c>a){ //a =1 b=3 c=2 + System.out.println(c); + }else if(c>a && a>b){// a =2 b=1 c= 3 + System.out.println(a); + }else if(b>a && a>c){// a=2 b=3 c=1 + System.out.println(a); + } + sc.close(); + } +} diff --git a/CodeShef/Easy Problems to Get Started/triangleEverywhere.java b/CodeShef/Easy Problems to Get Started/triangleEverywhere.java new file mode 100644 index 0000000..830eaee --- /dev/null +++ b/CodeShef/Easy Problems to Get Started/triangleEverywhere.java @@ -0,0 +1,34 @@ +//You're given the length of three sides a, b, and c respectively +//Now If these three sides can form an Equilateral Triangle then print 1, +// if these three sides can form an Isosceles Triangle then print 2, +// if these three sides can form a Scalene Triangle then print 3, otherwise print −1. +import java.util.*; +class triangleEverywhere { + public static void main(String[] args) { + Scanner sc = new Scanner(System.in); + double a = sc.nextInt(); + double b = sc.nextInt(); + double c = sc.nextInt(); + double s = (a+b+c)/2; + double area = s*(s-a)*(s-b)*(s-c); + area = Math.sqrt(area); + if(area>0){ + if(a==b&&b==c){ + System.out.println("1"); + }else if(a==b&&b!=c){ + System.out.println("2"); + }else if(a==c&&c!=a){ + System.out.println("2"); + }else if(b==c&&a!=c){ + System.out.println("2"); + }else if(a!=b&&b!=c){ + System.out.println("3"); + } + } + else{ + System.out.println("-1"); + } + sc.close(); + } +} +//complete \ No newline at end of file diff --git a/CodeShef/Easy Problems to Get Started/validAngleTriangle.java b/CodeShef/Easy Problems to Get Started/validAngleTriangle.java new file mode 100644 index 0000000..a205fe1 --- /dev/null +++ b/CodeShef/Easy Problems to Get Started/validAngleTriangle.java @@ -0,0 +1,18 @@ +//You're given the three angles a, b, and c respectively. +// Now check if these three angles can form a valid triangle with an area greater than 0 or not. +// Print "YES"(without quotes) if it can form a valid triangle with an area greater than 0, otherwise print "NO" (without quotes). +import java.util.*; +class validAngleTriangle { + public static void main(String[] args) { + Scanner sc = new Scanner(System.in); + int a = sc.nextInt(); + int b = sc.nextInt(); + int c = sc.nextInt(); + int sum = a+b+c; + if(sum == 180){ + }else{ + System.out.println("NO"); + } + sc.close(); + } +} diff --git a/CodeShef/Easy Problems to Get Started/validTriangle.java b/CodeShef/Easy Problems to Get Started/validTriangle.java new file mode 100644 index 0000000..50709d6 --- /dev/null +++ b/CodeShef/Easy Problems to Get Started/validTriangle.java @@ -0,0 +1,22 @@ +//You're given the length of three sides a, b, and c respectively. +//Now check if these three sides can form a triangle or not. +//Print "YES"(without quotes) if it can form a valid triangle with an area greater than 0, otherwise print "NO" (without quotes). +import java.util.*; +class validTriangle{ + public static void main(String args[]){ + Scanner sc = new Scanner(System.in); + double a = sc.nextInt(); + double b = sc.nextInt(); + double c = sc.nextInt(); + double s = (a+b+c)/2; + double area = (s*(s-a)*(s-b)*(s-c)); + area = Math.sqrt(area); + if(area>0){ + System.out.println("YES"); + }else{ + System.out.println("NO"); + } + sc.close(); + } +} +//complete diff --git a/CodeShef/INTRDSGN.java b/CodeShef/INTRDSGN.java new file mode 100644 index 0000000..cfaf603 --- /dev/null +++ b/CodeShef/INTRDSGN.java @@ -0,0 +1,21 @@ +import java.util.*; +public class INTRDSGN { + public static void main(String[] args) { + Scanner sc = new Scanner(System.in); + int T = sc.nextInt(); + for (int i = 0; i < T; i++) { + int x1 = sc.nextInt(); + int y1 = sc.nextInt(); + int x2 = sc.nextInt(); + int y2 = sc.nextInt(); + int sum1 = x1+y1; + int sum2 = x2+y2; + if(sum1<=sum2){ + System.out.println(sum1); + }else{ + System.out.println(sum2); + } + } + sc.close(); + } +} diff --git a/CodeShef/TFPAPER.java b/CodeShef/TFPAPER.java new file mode 100644 index 0000000..e5952e0 --- /dev/null +++ b/CodeShef/TFPAPER.java @@ -0,0 +1,16 @@ +/** + * TFPAPER + */ +import java.util.*; +public class TFPAPER { + public static void main(String[] args) { + Scanner sc = new Scanner(System.in); + int t = sc.nextInt(); + for (int i = 0; i < t; i++) { + int n = sc.nextInt(); + int k = sc.nextInt(); + System.out.println(n-k); + } + sc.close(); + } +} \ No newline at end of file diff --git a/CodeShef/fairpass.java b/CodeShef/fairpass.java new file mode 100644 index 0000000..4f48ada --- /dev/null +++ b/CodeShef/fairpass.java @@ -0,0 +1,19 @@ +import java.util.*; + +public class fairpass { + public static void main(String[] args) { + Scanner sc = new Scanner(System.in); + int T = sc.nextInt(); + for (int i = 0; i < T; i++) { + int N = sc.nextInt(); + int K = sc.nextInt(); + if(K>N){ + System.out.println("YES"); + } + else{ + System.out.println("NO"); + } + } + sc.close(); + } +} diff --git a/CodeShef/volcontrol.java b/CodeShef/volcontrol.java new file mode 100644 index 0000000..296800c --- /dev/null +++ b/CodeShef/volcontrol.java @@ -0,0 +1,22 @@ +// The first line contains a single integer T - the number of test cases. Then the test cases follow. +// The first and only line of each test case contains two integers X and Y - the initial volume and final volume of the TV. +// Output Format +// For each test case, output the minimum number of times Chef has to press a button to change the volume from X to Y. + +import java.util.*; +public class volcontrol { + public static void main(String[] args) { + Scanner sc = new Scanner(System.in); + int t = sc.nextInt(); + for(int i = 1; i<=t;i++){ + int x = sc.nextInt(); + int y = sc.nextInt(); + if((x-y) >= 0) { + System.out.println(x-y); + }else{ + System.out.println(y-x); + } + } + sc.close(); + } +}