Skip to content

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
marootushar committed Jun 9, 2021
1 parent f89a53e commit c6c0f94
Show file tree
Hide file tree
Showing 24 changed files with 1,027 additions and 0 deletions.
26 changes: 26 additions & 0 deletions AmateurHacker.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#include<bits/stdc++.h>
using namespace std;
int main()
{
int t;
cin>>t;
while(t--)
{
long long int n,k;
cin>>n>>k;
vector<long long int> a(n);
for(int i=0;i<n;i++)
cin>>a[i];
long long int total=0;
for(int i=0;i<n;i++)
{
int right=a[i]+k;
int index=lower_bound(a.begin(),a.end(),right)-a.begin();
if(index==n || a[index]!=right)
index--;
long long between = index-i-1;
total+=((between)*(between+1))/(long long)2;
}
cout<<total<<endl;
}
}
41 changes: 41 additions & 0 deletions AnalysingVirus.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#include <bits/stdc++.h>
using namespace std;

const int maxN = 5008;


void solve() {
int n;
int dp[maxN][maxN]={0};
vector<int> a(1), b;

cin >> n;
for (int i = 0; i < n; i++) {
int x; cin >> x;
if (x != a.back()) a.push_back(x);
}
n = a.size() - 1;

b = a;
reverse(b.begin() + 1, b.end());

for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
if (a[i] == b[j]) {dp[i][j] = dp[i-1][j-1] + 1;}
else {dp[i][j] = max(dp[i-1][j], dp[i][j-1]);}
}
}

cout << n - (dp[n][n] + 1)/2 << '\n';

}

int main() {
int t;
cin>>t;
while(t--)
{
solve();
}
return 0;
}
22 changes: 22 additions & 0 deletions Basketball Game.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#include<stdio.h>
#include<stdlib.h>
#include<bits/stdc++.h>
#include<process.h>

using namespace std;

int main(){
int t=1;
cin>>t;
while(t--){
int a, b, c;
cin>>a>>b>>c;
int total = a*c;
for(int i=1; ; i++){
if(c*b >= (total - b*i)){
cout<<i<<endl;
break;
}
}
}
}
27 changes: 27 additions & 0 deletions BreakTheCode.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#include<bits/stdc++.h>
using namespace std;
int main()
{
int t;
cin>>t;
while(t--)
{
//Input
int n;
int first;
cin>>n>>first;
vector<int> encrypted(n);
for(int i=0;i<n;i++)
cin>>encrypted[i];
//Main Logic
vector<int> ans;
ans.push_back(first);
for(int i=0;i<encrypted.size();i++)
ans.push_back(ans.back()^encrypted[i]);

//Output
for(int i=0;i<ans.size();i++)
cout<<ans[i]<<" ";
cout<<endl;
}
}
101 changes: 101 additions & 0 deletions CardBattle.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
package Solutions;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
import java.util.*;

public class CardBattle {

static class FastReader {
BufferedReader br;
StringTokenizer st;

public FastReader() {
br = new BufferedReader(new InputStreamReader(System.in));
}

String next() {
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}

int nextInt() {
return Integer.parseInt(next());
}

long nextLong() {
return Long.parseLong(next());
}

double nextDouble() {
return Double.parseDouble(next());
}

String nextLine() {
String str = "";
try {
str = br.readLine();
} catch (IOException e) {
e.printStackTrace();
}
return str;
}
}

// ===================================================================================================================================================

public static void main(String args[]) {
FastReader in = new FastReader();
int t = in.nextInt();
while (t-- > 0) {
int n = in.nextInt();
int k1 = in.nextInt();
ArrayDeque<Integer> a = new ArrayDeque<Integer>();
for (int i = 0; i < k1; i++) {
int num = in.nextInt();
a.add(num);
}
int k2 = in.nextInt();
ArrayDeque<Integer> b = new ArrayDeque<Integer>();
for (int i = 0; i < k2; i++) {
int num = in.nextInt();
b.add(num);
}
boolean draw = false;
int moves = 0;
while (!a.isEmpty() && !b.isEmpty()) {
int a1 = a.removeFirst();
int b1 = b.removeFirst();
if (a1 > b1) {
a.add(b1);
a.add(a1);
moves++;
} else {
b.add(a1);
b.add(b1);
moves++;
}
if (moves > 110) {
draw = true;
break;
}
}

if (draw) {
System.out.println(-1);
} else {
System.out.print(moves + " ");
int win = (a.isEmpty()) ? 2 : 1;
System.out.println(win);
}
}
}
}
82 changes: 82 additions & 0 deletions Chaos.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
package Solutions;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;


public class Chaos {

static class FastReader {
BufferedReader br;
StringTokenizer st;

public FastReader() {
br = new BufferedReader(new InputStreamReader(System.in));
}

String next() {
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}

int nextInt() {
return Integer.parseInt(next());
}

long nextLong() {
return Long.parseLong(next());
}

double nextDouble() {
return Double.parseDouble(next());
}

String nextLine() {
String str = "";
try {
str = br.readLine();
} catch (IOException e) {
e.printStackTrace();
}
return str;
}
}

// ===================================================================================================================================================


public static void main(String args[]) {
FastReader in = new FastReader();
int t = in.nextInt();
String ans[] = new String[t];
for(int tc = 0;tc<t;tc++) {
String s = in.nextLine();
int n = s.length();
String match = "chaos";
int j = 0;
String found = "NO";
for(int i = 0;i<n;i++) {
char ch = s.charAt(i);
if(ch == match.charAt(j)) {
j++;
}
if(j==match.length()) {
found = "YES";
break;
}
}
ans[tc] = found;
}
for(int i = 0;i<t;i++) {
System.out.println(ans[i]);
}
}
}
25 changes: 25 additions & 0 deletions CodingContest.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#include<bits/stdc++.h>
using namespace std;
int main()
{
int t;
cin>>t;
while(t--)
{
int n;
cin>>n;
vector<int> points(n);
for(int i=0;i<n;i++)
{
cin>>points[i];
}
int mx=0;
int sum=0;
for(int i=0;i<n;i++)
{
sum=sum+points[i];
mx=max(mx,sum);
}
cout<<mx<<endl;
}
}
29 changes: 29 additions & 0 deletions CubaLibre.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define endl "\n"

void solve()
{
ll i, p, q, r;
cin >> p >> q >> r;
for (i = p; i >= 0; i--)
{
if (2 * i <= q && 4 * i <= r)
break;
}
cout << 7 * i << endl;
}

int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
long long t = 1;
cin >> t;
while (t--)
{
solve();
}
return 0;
}
Loading

0 comments on commit c6c0f94

Please sign in to comment.