Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
Simar65 committed Aug 11, 2023
1 parent 53b0e83 commit 283c197
Show file tree
Hide file tree
Showing 13 changed files with 545 additions and 0 deletions.
32 changes: 32 additions & 0 deletions Array Color.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#include<iostream>
using namespace std;

int main(){

int t;
//int sum = 0;

cin>>t;

while(t--){
int sum = 0;
int a,i;
int n;
cin>>a;
for(i=0;i<a;i++){
cin>>n;
sum=sum+n;
}
if(sum%2 == 0){
cout<<"YES"<<endl;
}

else{
cout<<"NO"<<endl;

}

}


}
28 changes: 28 additions & 0 deletions Come-Together.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#include<iostream>
using namespace std;

int main(){
int t;
cin>>t;
int a,b,c,d,x,y;

while (t--)
{
cin>>x>>y; // CURRENT LOCATION
cin>>a>>b;// BOB's location
cin>>c>>d;// Carol's Location

if(c<=x && x<=a && d<=y && y<=b || b<=y && y<=d && a<=x && x<=c){
cout<<"1"<<endl;
}

else{
int r = (abs(a-x) + abs(b-y) + 1) + (abs(c-x) + abs(d-y) + 1) - (abs(a-c) + abs(b-d));
int s = ((r+1)/2);
cout<<s<<endl;

}

}

}
12 changes: 12 additions & 0 deletions Decoding.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#include<stdio.h>
#include<iostream>
using namespace std;

int main(){
int x;
cin>>x;
string s;
cin>>s;


}
45 changes: 45 additions & 0 deletions Forbidden Interger.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#include<iostream>
using namespace std;

int main(){

int t;
cin>>t;

while(t--){
int n,k,x;
int i,j;
bool check = true;
cin>>n>>k>>x;

if(k==x==1){
cout<<"NO"<<endl;
}

if( n%2 !=0 && k==2 && x==1){
cout<<"NO"<<endl;
}

if(x!= 1){
cout<<"Yes"<<endl;
cout<<n*1<<endl;
for(j=1;j<=(n*1);j++){
cout<<"1"<<" ";
}
cout<<endl;
}


if(n % 2 == 0){

cout<<"YES"<<endl;
cout<<n/2<<endl;
for(i=1;i<=n;i++){
cout<<"2"<<" ";
}
cout<<endl;
}

}

}
60 changes: 60 additions & 0 deletions Max Rounding.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
#include <iostream>
#include<bits/stdc++.h>
#include<string.h>
#include<cmath>

using namespace std;

int countDigit(long long n)
{
int count=0;
while (n != 0) {
count++;
n = n / 10;
}
return count;
}

int main() {
int t;
cin >> t;
int n;
int i,j,digit,temp,k,h;
while(t--){
cin >> n;
int temp=n;
int original;
original = n;
int maxnum=max(n,0);
h = countDigit(n);
if(n < 5){
cout << n << endl;
}
else if(n>=5 && n<=10){
cout << 10 << endl;
}
else{
for(k=1; k<=h;k++){
digit = temp % 10;
if(digit >= 5){
n = n + pow(10,k) - (pow(10,k-1)*digit);
}
else{
n = n - (pow(10,k-1) * digit);
}
temp=n/pow(10,k);
maxnum=max(maxnum,n);
temp%=10;
}
cout<<maxnum<<endl;
}
}
}








25 changes: 25 additions & 0 deletions Oridinary Numbers.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--)
{
long long n, count=0, start;
cin >> n;
for(int i=1; i<=9; i++)
{
start=i;
while(start<=n)
{
count++;
start=start*10+i;
}
}
cout << count << endl;
}
}
29 changes: 29 additions & 0 deletions Polycarp and Coins.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#include<iostream>
using namespace std;


int main(){
int t;
cin>>t;
int a,b;

while(t--){
cin>>a;
if(a % 3 == 0){
cout<<a/3<<" "<<a/3<<endl;
}

else if( a % 3 == 1){
cout<<a/3 + 1<<" "<<a/3<<endl;
}

else if(a % 3 == 2){
cout<<a/3 <<" "<<a/3 + 1 <<endl;
}




}

}
16 changes: 16 additions & 0 deletions Socks.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#include<iostream>
using namespace std;

#include <iostream>
using namespace std;

int main() {
int n,m;
cin>>n>>m;
int a = n-1;
int b = m-1;
int result=(a)/(b);
cout<<n+result;

return 0;
}
67 changes: 67 additions & 0 deletions Two Arrays and Swaps.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
#include <iostream>
#include <algorithm>
#include <numeric>
using namespace std;

int smallest(int arr[], int size) {
if (size <= 0) {
return -1;
}

int smallest = arr[0];

for (int i = 1; i < size; ++i) {
if (arr[i] < smallest) {
smallest = arr[i];
}
}

return smallest;
}

int findIndex(int arr[], int n, int target) {
for (int i = 0; i < n; i++) {
if (arr[i] == target) {
return i;
}
}
return -1;
}

int main() {

int t;
cin >> t;

while (t--) {
int x, n;
cin >> x >> n;

int a[x];
int b[x];

for (int i = 0; i < x; i++) {
cin >> a[i];
}

for (int i = 0; i < x; i++) {
cin >> b[i];
}

while (n--) {
int maxBIndex = distance(b, max_element(b, b + x));
int minA = smallest(a, x);
int minAIndex = findIndex(a, x, minA);

if (minAIndex != -1 ) {
swap(a[minAIndex], b[maxBIndex]);
sort(a,a+x);
sort(b,b+x);
}
}

cout << accumulate(a, a + x, 0) << endl;
}

return 0;
}
40 changes: 40 additions & 0 deletions Vika.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#include<iostream>
#include<cstdlib>
using namespace std;


int main(){

int t,i,j,n,m;
int k,a,b,x,y;
cin>>t; //test cases.

while(t--){
bool check = true;
cin>>n>>m; //size of mall.
cin>>k; //number of Vika's friends.
cin>>x>>y; //Vika's location

for(i=1;i<=k;i++){
cin>>a>>b; // location of each friend;
if((abs(x-a) + abs(y-b)) % 2 == 0){
check = false;
}
}
if(!check){
cout<<"NO"<<endl;
}
if(check){
cout<<"YES"<<endl;
}


}
}







Loading

0 comments on commit 283c197

Please sign in to comment.