Skip to content

Commit a9ae970

Browse files
authored
Merge branch 'master' into add-comb-sort
2 parents 1af5cc2 + 8f3579e commit a9ae970

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+1823
-21
lines changed

CodeChef_problems/CVDRUN.cpp

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
//************************** it's all about practice ***********************
2+
#include<bits/stdc++.h>
3+
using namespace std;
4+
//**** Abbrevations ****
5+
typedef long long ll;
6+
typedef unsigned long long ull;
7+
typedef long double ld;
8+
//**** STL ****
9+
#define pb push_back
10+
#define pf push_front
11+
#define ppb pop_back
12+
#define ppf pop_front
13+
#define ff first
14+
#define ss second
15+
#define mp make_pair
16+
#define ALL(x) x.begin(), x.end()
17+
//**** some I/O ****
18+
#define no cout << "NO\n"
19+
#define yes cout << "YES\n"
20+
//**** Fast I/O ****
21+
#define FAST_IO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
22+
//**** Short Code ****
23+
#define tc ll t;cin>>t;while(t--)
24+
#define fi(a,b) for(ll i=a;i<b;i++)
25+
#define fj(a,b) for(ll j=a;j<b;j++)
26+
#define fk(a,b) for(ll k=a;k<b;k++)
27+
/*---------------------------------------------------------------------------*/
28+
int main()
29+
{
30+
FAST_IO
31+
tc
32+
{
33+
int n,k,x,y;
34+
cin>>n>>k>>x>>y;
35+
bool c=false;
36+
int i=x;
37+
if(x==y)
38+
c=true;
39+
else
40+
i=(i+k)%n;
41+
while(i!=x)
42+
{
43+
if(i==y)
44+
{
45+
c=true;
46+
break;
47+
}
48+
else
49+
i=(i+k)%n;
50+
}
51+
if(c==true)
52+
yes;
53+
else
54+
no;
55+
56+
}
57+
return 0;
58+
}
59+
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#include <bits/stdc++.h>
2+
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
3+
typedef unsigned long long int unt;
4+
using namespace std;
5+
6+
bool Prime(unt n){
7+
8+
if (n <= 1)
9+
return false;
10+
if (n <= 3)
11+
return true;
12+
13+
if (n % 2 == 0 || n % 3 == 0)
14+
return false;
15+
16+
for (unt i = 5; i * i <= n; i = i + 6)
17+
if (n % i == 0 || n % (i + 2) == 0)
18+
return false;
19+
20+
return true;
21+
}
22+
23+
void printPrime(unt a,unt n){
24+
for (unt i = a; i <= n; i++){
25+
if(Prime(i))
26+
cout <<i<<'\n';
27+
}
28+
}
29+
30+
int main(){
31+
fast;
32+
unt t;
33+
cin>>t;
34+
while(t--){
35+
int a,n;
36+
cin>>a>>n;
37+
printPrime(a,n);
38+
}
39+
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/**************************************************************************
2+
* $Id$
3+
* File:
4+
*
5+
* Purpose:
6+
*
7+
* Author: Sanchit Gupta (CS19B071)
8+
*
9+
* Created:
10+
*
11+
* Last modified:
12+
*
13+
* Bugs:
14+
*
15+
* Change Log:
16+
*
17+
* While(!(succeed==try());
18+
**************************************************************************/
19+
#include<iostream>
20+
#include<bits/stdc++.h>
21+
22+
using namespace std;
23+
24+
int main()
25+
{
26+
int t;
27+
cin>>t;
28+
while(t--)
29+
{
30+
long long int n;
31+
cin>>n;
32+
long long int sum1=0,sum2=0;
33+
long long int current=2,i=1;
34+
while(i<(n/2))
35+
{
36+
sum1=sum1+current;
37+
current=current*2;
38+
i++;
39+
}
40+
while(i<n)
41+
{
42+
sum2=sum2+current;
43+
current=current*2;
44+
i++;
45+
}
46+
sum1=sum1+current;
47+
cout<<abs(sum1-sum2)<<endl;
48+
}
49+
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/**************************************************************************
2+
* $Id$
3+
* File:
4+
*
5+
* Purpose:
6+
*
7+
* Author: Sanchit Gupta (CS19B071)
8+
*
9+
* Created:
10+
*
11+
* Last modified:
12+
*
13+
* Bugs:
14+
*
15+
* Change Log:
16+
*
17+
* While(!(succeed==try());
18+
**************************************************************************/
19+
#include <bits/stdc++.h>
20+
using namespace std;
21+
22+
int main(){
23+
int t; cin>>t;
24+
while (t--)
25+
{
26+
int n,k;
27+
cin>>n,k;
28+
set<int>s;
29+
for (int i=0;i<n;i++){
30+
int a;
31+
cin>>a;
32+
s.insert(a);
33+
}
34+
if (s.size()>k){
35+
cout<<-1<<endl;
36+
return;
37+
}
38+
cout<<n*k<<endl;
39+
for (int i=0;i<N;i++){
40+
for (int b:s)
41+
cout<<b<<' ';
42+
for (int j=0;j<k-(int)s.size();j++)
43+
cout<<1<<' ';
44+
}
45+
cout<<endl;
46+
}
47+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import java.io.*;
2+
import java.util.*;
3+
4+
public class Solution {
5+
6+
public static void main(String[] args)
7+
{
8+
Scanner sc = new Scanner(System.in);
9+
int n = sc.nextInt();
10+
for(int i=0; i<n; i++)
11+
{
12+
int c = 0;
13+
int p = sc.nextInt();
14+
if(p==1)
15+
System.out.println("Not prime");
16+
for(int j=2; j*j<=p;j++)
17+
{
18+
if(p%j==0)
19+
{
20+
System.out.println("Not prime");
21+
c++;
22+
break;
23+
}
24+
}
25+
if(c==0 && p!=1)
26+
System.out.println("Prime");
27+
}
28+
}
29+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
2+
/************************************
3+
Java's System.out.printf function can be used to print formatted output. The purpose of this exercise is to test your understanding of formatting output using printf.
4+
To get you started, a portion of the solution is provided for you in the editor; you must format and print the input to complete the solution.
5+
Input Format
6+
Every line of input will contain a String followed by an integer.
7+
Each String will have a maximum of alphabetic characters, and each integer will be in the inclusive range from to .
8+
Output Format
9+
In each line of output there should be two columns:
10+
The first column contains the String and is left justified using exactly characters.
11+
The second column contains the integer, expressed in exactly digits; if the original input has less than three digits, you must pad your output's leading digits with zeroes.
12+
Sample Input
13+
java 100
14+
cpp 65
15+
python 50
16+
Sample Output
17+
================================
18+
java 100
19+
cpp 065
20+
python 050
21+
================================
22+
Explanation
23+
Each String is left-justified with trailing whitespace through the first characters. The leading digit of the integer is the character, and each integer that was less than digits now has leading zeroes.
24+
***************************************/
25+
import java.util.Scanner;
26+
27+
public class Solution {
28+
29+
public static void main(String[] args) {
30+
Scanner sc=new Scanner(System.in);
31+
System.out.println("================================");
32+
for(int i=0;i<3;i++){
33+
String s1=sc.next();
34+
int x=sc.nextInt();
35+
System.out.printf("%-15s%03d%n", s1, x);
36+
//Complete this line
37+
}
38+
System.out.println("================================");
39+
40+
}
41+
}
42+
43+

Hackerrank/java/Java_2D_Array.java

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import java.io.*;
2+
import java.math.*;
3+
import java.security.*;
4+
import java.text.*;
5+
import java.util.*;
6+
import java.util.concurrent.*;
7+
import java.util.regex.*;
8+
9+
public class Solution {
10+
11+
12+
13+
private static final Scanner scanner = new Scanner(System.in);
14+
15+
public static void main(String[] args) {
16+
int[][] arr = new int[6][6];
17+
int max = -70;
18+
19+
for (int i = 0; i < 6; i++) {
20+
String[] arrRowItems = scanner.nextLine().split(" ");
21+
scanner.skip("(\r\n|[\n\r\u2028\u2029\u0085])?");
22+
23+
for (int j = 0; j < 6; j++) {
24+
int arrItem = Integer.parseInt(arrRowItems[j]);
25+
arr[i][j] = arrItem;
26+
}
27+
}
28+
29+
for(int i=0;i<4;i++)
30+
{
31+
for(int j=0;j<4;j++)
32+
{
33+
int sum = arr[i][j] + arr[i][j+1] + arr[i][j+2] + arr[i+1][j+1] + arr[i+2][j] + arr[i+2][j+1] + arr[i+2][j+2];
34+
if(sum >= max)
35+
max = sum;
36+
}
37+
}
38+
39+
System.out.println(max);
40+
41+
scanner.close();
42+
}
43+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import java.io.*;
2+
import java.util.*;
3+
4+
public class Solution {
5+
6+
public static void main(String[] args) {
7+
Scanner scan = new Scanner(System.in);
8+
String s = scan.nextLine().trim();
9+
10+
String[] str = s.split("[ !,?._'@]+");
11+
int l = str.length;
12+
if(s.compareTo("")==0)
13+
System.out.println(0);
14+
else
15+
{
16+
System.out.println(l);
17+
for(int i=0;i<l;i++)
18+
System.out.println(str[i]);
19+
}
20+
scan.close();
21+
}
22+
}

0 commit comments

Comments
 (0)