Skip to content
This repository has been archived by the owner on Dec 19, 2022. It is now read-only.

Commit

Permalink
Merge pull request #301 from shubhrai2811/main
Browse files Browse the repository at this point in the history
added codeforces solutions to CPP
  • Loading branch information
Almas-Ali authored Oct 30, 2022
2 parents 081ed2f + 2ac460e commit 18f6a35
Show file tree
Hide file tree
Showing 20 changed files with 584 additions and 0 deletions.
27 changes: 27 additions & 0 deletions C++/CodeForces Solutions/AhAb AnD gCd.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#include<iostream>
#include<bits/stdc++.h>

using namespace std;
void solve(int n){
for(int i=1;i<n;i++){
int a=i;
int b=n-i;
int ans1=__gcd(a,b);
int ans2=lcm(a,b);
if(ans1+ans2==n){
cout<<a<<" "<<b<<endl;
break;
}

}
}
int main(){
int t;
cin>>t;
for(int i=0;i<t;i++){;
int x;
cin>>x;
solve(x);
}
return 0;
}
24 changes: 24 additions & 0 deletions C++/CodeForces Solutions/Heist.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#include<iostream>
#include<bits/stdc++.h>

using namespace std;
int main(){
int n;
cin>>n;
int count=0;
int arr[n];
for (int i = 0; i < n; i++)
{
cin>>arr[i];

}
sort(arr,arr+(n));
int y = arr[n-1];
int x= arr[0];

int ans = y-x-n+1;

std::cout<<ans<<endl;

return 0;
}
47 changes: 47 additions & 0 deletions C++/CodeForces Solutions/Sereja and Dima.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#include<iostream>
#include<bits/stdc++.h>
#define ll long long
using namespace std;

int main(){
ll n;
cin>>n;
ll arr[n+2];
ll srej=0,dim=0;
int left=1,right=n,chance=1;
for (int i = 1; i < n+1; i++)
{
cin>>arr[i];
}
while(right>=left){
if(chance%2==1){

if(arr[left]>=arr[right]){
srej+=arr[left++];

}
else{
srej+=arr[right--];

}
chance++;
}
else if(chance%2==0){

if(arr[left]>=arr[right]){
dim+=arr[left++];

}
else{
dim+=arr[right--];

}
chance++;
}


}
cout<<srej<<" "<<dim<<endl;

return 0;
}
20 changes: 20 additions & 0 deletions C++/CodeForces Solutions/buy_a_shovel.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#include<iostream>
#include<bits/stdc++.h>

using namespace std;
int main(){
int k,r,h=1,i=0,j=1;
bool b=true;
cin>>k>>r;

while(b){
i++;
h=k*i;
if(h%10==0 or h%10==r){
b=false;
}
}
cout<<i;

return 0;
}
47 changes: 47 additions & 0 deletions C++/CodeForces Solutions/captian flint.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#include<iostream>
#include<bits/stdc++.h>

using namespace std;

void solve(int n){
int rem1= n-16;
if(n<=30){
cout<<"NO"<<endl;
}
else{
int d1=2*7;
int d2=3*5;
int d3=3*7;
int d4=2*11;
int rem2=rem1-d1;
int rem3=rem1-d2;
int rem4=rem1-d3;
int rem5=rem1-d4;
if(rem2>0 and rem2!=d1 and rem2!= 6 and rem2!=10){
cout<<"YES"<<endl;
cout<<6<<" "<<10<<" "<<d1<<" "<<rem2<<endl;
}
else if(rem3>0 and rem3!=d2 and rem3!= 6 and rem3!=10){
cout<<"YES"<<endl;
cout<<6<<" "<<10<<" "<<d2<<" "<<rem3<<endl;
}
else if(rem4>0 and rem4!=d3 and rem4!= 6 and rem4!=10){
cout<<"YES"<<endl;
cout<<6<<" "<<10<<" "<<d3<<" "<<rem4<<endl;
}
else if(rem5>0 and rem5!=d4 and rem5!= 6 and rem5!=10){
cout<<"YES"<<endl;
cout<<6<<" "<<10<<" "<<d4<<" "<<rem5<<endl;
}
}
}
int main(){
int t;
cin>>t;
for(int i=0;i<t;i++){;
int n;
cin>>n;
solve(n);
}
return 0;
}
21 changes: 21 additions & 0 deletions C++/CodeForces Solutions/check.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#include<iostream>
#include<bits/stdc++.h>

using namespace std;
int main(){
string s1="best";
string s2="cost";
int sum1=0;
int sum2=0;
for (int i = 0; i < s1.size(); i++)
{
sum1+= s1[i];
}
for (int i = 0; i < s2.size(); i++)
{
sum2+= s2[i];
}

cout<<sum1-sum2<<endl;
return 0;
}
28 changes: 28 additions & 0 deletions C++/CodeForces Solutions/chosing_teams.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#include<iostream>
#include<bits/stdc++.h>

using namespace std;
int main(){
int n,k,count=0;
cin>>n>>k;
int arr[n];

for (int i = 0; i <n; i++)
{
cin>>arr[i];
if((5-arr[i])>=k){
count++;
}
}

int ans=count/3;
if(ans>=1){
cout<<ans<<endl;
}
else{
cout<<0<<endl;
}


return 0;
}
29 changes: 29 additions & 0 deletions C++/CodeForces Solutions/divan and a store.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#include<iostream>
#include<bits/stdc++.h>

using namespace std;
int main(){
int t;
cin>>t;
for(int i=0;i<t;i++){;
int n,l,r,k,count=0;
cin>>n>>l>>r>>k;
int left=k;
int arr[n];
for (int i = 0; i < n; i++)
{
cin>>arr[i];
}
sort(arr,arr+(n-1));
for (int i = 0; i < n; i++)
{
if(arr[i]>=l && arr[i]<=r and arr[i]<=left){
left-=arr[i];
count++;
}
}
cout<<count<<endl;

}
return 0;
}
29 changes: 29 additions & 0 deletions C++/CodeForces Solutions/lcm problem.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#include <iostream>
#include <bits/stdc++.h>

using namespace std;

int main()
{
int t,x=0,y=0;
cin >> t;
for (int i = 0; i < t; i++)
{
int l, r;
cin >> l >> r;
int x=l,y=2*l;

if(y<=r){


cout<<x<<" "<<y<<endl;

}
else{
cout<<-1<<" "<<-1<<endl;
}
}


return 0;
}
48 changes: 48 additions & 0 deletions C++/CodeForces Solutions/most similar words.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#include<iostream>
#include<bits/stdc++.h>

using namespace std;

int sdif(string s1,string s2){
int sum1=0;
// int sum2=0;
int diff;
for (int i = 0; i < s1.size(); i++)
{
sum1+= abs(s1[i]-s2[i]);
}
// for (int i = 0; i < s2.size(); i++)
// {
// sum2+= s2[i];
// }

return sum1;
}

int main(){
int t;
cin>>t;
for(int i=0;i<t;i++){;
int m,n;
cin>>n>>m;
vector <string> arr(n);
int mini=INT_MAX;
int d;
for (int i = 0; i < n; i++)
{
cin>>arr[i];
}
for (int i = 0; i < n; i++)
{
for (int j = i+1;j < n; j++)
{
d=sdif(arr[i],arr[j]);
mini=min(mini,d);
}
}


cout<<mini<<endl;
}
return 0;
}
23 changes: 23 additions & 0 deletions C++/CodeForces Solutions/ordinary_numbers.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#include<iostream>
#include<bits/stdc++.h>

using namespace std;
int solve(int n){
int s = 0;
for (int p = 1; p <= n; s++){
p = p / (p % 10) * (p % 10 + 1);
if (p % 10 == 0)
p++;
}
return s;
}
int main(){
int t,count=0;
cin>>t;
for(int i=0;i<t;i++){;
int n;
cin>>n;
cout<<solve(n)<<endl;
}
return 0;
}
26 changes: 26 additions & 0 deletions C++/CodeForces Solutions/polycarp_and_coins.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#include<iostream>
#include<bits/stdc++.h>

using namespace std;
int main(){
int t;
cin>>t;
for(int i=0;i<t;i++){;
int n,c1,c2;
cin>>n;
int res = n%3;
if(res==0){
c1=c2=n/3;
}
else if(res==1){
c1=n/3+1;
c2=n/3;
}
else if(res==2){
c1=n/3;
c2=n/3+1;
}
cout<<c1<<" "<<c2<<endl;
}
return 0;
}
3 changes: 3 additions & 0 deletions C++/CodeForces Solutions/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
here i'm posting Codeforces Solutions

updating it for git ssh
Loading

0 comments on commit 18f6a35

Please sign in to comment.