Skip to content

Commit

Permalink
Uploaded CodeChef Contests' accepted submissions
Browse files Browse the repository at this point in the history
  • Loading branch information
SambhavJain74 authored Sep 24, 2023
1 parent 987515c commit 8f2d6cd
Show file tree
Hide file tree
Showing 12 changed files with 628 additions and 0 deletions.
79 changes: 79 additions & 0 deletions CodeChef/starters100div3/Ant.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
#include<bits/stdc++.h>
#define yes cout<<"Yes"<<"\n"
#define no cout<<"No"<<"\n"
#define ent cout<<"\n";
#define endl "\n"
#define int long long
using ll=long long;
using namespace std;

void solve()
{
int n;
cin>>n;
if(n&1)
{
cout<<-1;
return;
}
for(int i=0;i<n;i++)
{
cout<<i<<" ";
}
cout<<"\n";
for(int i=1;i<n;i++)
{
if(i&1)
{
for(int j=n-i;j>=0;j--)
{
cout<<j<<" ";
}
for(int j=n-1;j>n-i;j--)
{
cout<<j<<" ";
}
}
else
{
for(int j=n-i;j<n;j++)
{
cout<<j<<" ";
}
for(int j=0;j<n-i;j++)
{
cout<<j<<" ";
}
}
cout<<"\n";
}
string first="",second="",up="";
for(int i=1;i<=n-2;i++)
{
first+="R";
second+="L";
up+="U";
}
cout<<first+"RD";
for(int i=1;i<n-1;i++)
{
if(i&1)
{
cout<<second+"D";
}
else
{
cout<<first+"D";
}
}
cout<<second+"L";
cout<<up+"U"<<"\n";
}

int32_t main()
{
ios::sync_with_stdio(0);
cin.tie(0);
solve();
return 0;
}
33 changes: 33 additions & 0 deletions CodeChef/starters100div3/Chocolate_Distribution.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#include<bits/stdc++.h>
#define yes cout<<"Yes"<<"\n"
#define no cout<<"No"<<"\n"
#define endl "\n"
#define int long long
using ll=long long;
using namespace std;

void solve()
{
int n;
cin>>n;
if(n&1)
{
cout<<2<<" "<<2<<" "<<(n-4)<<"\n";
return;
}
cout<<2<<" "<<(n-2)/2<<" "<<(n-2)/2<<"\n";
return;
}

int32_t main()
{
ios::sync_with_stdio(0);
cin.tie(0);
int t;
cin>>t;
while(t--)
{
solve();
}
return 0;
}
61 changes: 61 additions & 0 deletions CodeChef/starters100div3/Prime_Permutation.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
#include<bits/stdc++.h>
#define yes cout<<"Yes"<<"\n"
#define no cout<<"No"<<"\n"
#define endl "\n"
#define int long long
using ll=long long;
using namespace std;

bool isp(int n)
{
for(int i=2;i*i<=n;i++)
{
if(n%i==0)
{
return false;
}
}
return true;
}

vector<vector<int>>vec={{3,4,1,2},{4,5,1,2,3},{4,5,6,1,2,3},{6,7,1,2,3,4,5}};

void solve()
{
int n;
cin>>n;
if(n<=3)
{
cout<<-1;
return;
}
int t=n/4-1,i=0;
while(i<t)
{
for(auto j:vec[0])
{
cout<<i*4+j<<" ";
}
i++;
}
t=n-4*t;
for(auto j:vec[t-4])
{
cout<<i*4+j<<" ";
}
return;
}

int32_t main()
{
ios::sync_with_stdio(0);
cin.tie(0);
int t;
cin>>t;
while(t--)
{
solve();
cout<<"\n";
}
return 0;
}
49 changes: 49 additions & 0 deletions CodeChef/starters100div3/Stamps_100.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#include<bits/stdc++.h>
#define yes cout<<"Yes"<<"\n"
#define no cout<<"No"<<"\n"
#define endl "\n"
#define int long long
using ll=long long;
using namespace std;

void solve()
{
int n;
string s;
cin>>n>>s;
int i=0;
while(s[i]=='0')
{
cout<<0;
i++;
}
if(i<=n-2)
{
cout<<1;
i++;
while(i<n)
{
cout<<0;
i++;
}
return;
}
else
{
cout<<s.substr(i);
}
}

int32_t main()
{
ios::sync_with_stdio(0);
cin.tie(0);
int t;
cin>>t;
while(t--)
{
solve();
cout<<endl;
}
return 0;
}
27 changes: 27 additions & 0 deletions CodeChef/starters100div3/Trade_Surplus.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#include<bits/stdc++.h>
#define yes cout<<"Yes"<<"\n"
#define no cout<<"No"<<"\n"
#define endl "\n"
#define int long long
using ll=long long;
using namespace std;

bool solve()
{
int a,b,c,d;
cin>>a>>b>>c>>d;
return (b+d>a+c)?true:false;
}

int32_t main()
{
ios::sync_with_stdio(0);
cin.tie(0);
int t;
cin>>t;
while(t--)
{
solve()?yes:no;
}
return 0;
}
57 changes: 57 additions & 0 deletions CodeChef/starters101div2/Lockpicking_Chef.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
#include<bits/stdc++.h>
#define yes cout<<"Yes"<<"\n"
#define no cout<<"No"<<"\n"
#define enter cout<<"\n"
#define endl "\n"
#define all(a) a.begin(),a.end()
#define pb push_back
#define int long long
using ll=long long;
using ull=unsigned long long;
using namespace std;

bool sortbycond(const pair<int,int>& a,const pair<int,int>& b)
{
if(a.first!=b.first)
{
return (a.first<b.first);
}
else
{
return (a.second>b.second);
}
}

int solve()
{
int n,m,ans=LONG_LONG_MAX,curr;
string s,k;
cin>>n>>m>>s>>k;
for(int i=0;i<=n-m;i++)
{
curr=0;
for(int j=0;j<m;j++)
{
curr+=min(abs(s[i+j]-k[j]),10-abs(s[i+j]-k[j]));
}
if(curr==0)
{
return 0;
}
ans=min(ans,curr);
}
return ans;
}

int32_t main()
{
ios::sync_with_stdio(0);
cin.tie(0);
int t;
cin>>t;
while(t--)
{
cout<<solve()<<"\n";
}
return 0;
}
Loading

0 comments on commit 8f2d6cd

Please sign in to comment.