Skip to content

Commit

Permalink
First commit
Browse files Browse the repository at this point in the history
  • Loading branch information
N-E-W-T-O-N authored Oct 3, 2020
0 parents commit 77e6b85
Show file tree
Hide file tree
Showing 22 changed files with 1,012 additions and 0 deletions.
2 changes: 2 additions & 0 deletions 1.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
HARI_b@l
microsoft office
13 changes: 13 additions & 0 deletions 2d_vector_int.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#include<iostream>
#include<vector>
using namespace std;
int main()
{
vector<vector<int> > v(6,vector < int> (6,0)) ;
for(int i =0 ; i<6;i++)
{
for(int j=0 ;j<6 ; j++)
cout<<v[i][j]<<" " ;
cout<<endl ;
}
}
54 changes: 54 additions & 0 deletions 3_d_shapes.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#include<iostream>
#include<vector>
using namespace std;

int surface(vector<vector <int>> a , int h , int w)
{
//top bottom surface
long sum = 2*h*w ;
int i,j;

for(j=0 ; j<w ; j++)
{
sum+=a[0][j]+a[h-1][j] ;
for( i=0 ; i<h-1 ; i++)
{
if(a[i][j]!=a[i+1][j])
{
sum+=abs(a[i][j]-a[i+1][j]) ;
}
}
}

for (i=0;i<h;i++)
{
sum+=a[i][0]+a[i][w-1] ;
for(j=0;j<w-1;j++)
{
if(a[i][j]!=a[i][j+1])
{
sum+=abs(a[i][j]-a[i][j+1]) ;
}
}
}

return sum;
}

int main()
{
int h,w;
vector<vector <int>> a;
cin>>h>>w ;
for(int i=0 ; i<h ; i++)
{
vector<int> b(w);
for(int j=0 ; j<w ; j++)
{
cin>>b[j];
}
a.push_back(b);
}
cout<<surface(a,h,w);
return 0;
}
41 changes: 41 additions & 0 deletions Beautiful Days at the Movies.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#include <bits/stdc++.h>

using namespace std;



int reverse_int(int i)
{
int r=0;
while(i>0)
{
r=r*10+i%10;
i=i/10;
}
return r ;
}
// Complete the beautifulDays function below.
int beautifulDays(int i, int j, int k) {
int count=0 ;
while(i<=j)
{
if(abs(i-reverse_int(i))%k==0)
count++ ;
i++ ;
}
return count ;
}

int main()
{

int i , j , k ;
cout<<"Enter\n";
cin>>i>>j>>k ;
int result = beautifulDays(i, j, k);

cout<<result;


return 0;
}
22 changes: 22 additions & 0 deletions Cat_and_a_Mouse.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#include<bits/stdc++.h>

using namespace std;
int main()
{
cout<<"Enter\n";
int q,x,y,z;
cin>>q;
while(q--)
{
cin>>x;
cin>>y;
cin>>z;
if(abs(x-z)==abs(y-z))
cout<<"Mouse C";
else if(abs(x-z)<abs(y-z))
cout<<"Cat A" ;
else cout<<"Cat B";
}
return 0 ;

}
23 changes: 23 additions & 0 deletions ackermann.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#include<iostream>
using namespace std ;
int a(int i,int j)
{
if(i==0)
return j+1;
else if(j==0)
{
return a(i-1,1);
}
else
{
return a(i-1,a(i,j-1)) ;
}

}
int main()
{
int n;
cin>>n;
for(int i=0;i<=n;i++)
cout<<a(n,i)<<" ";
}
43 changes: 43 additions & 0 deletions activity_selection.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#include<bits/stdc++.h>
using namespace std;
bool compare(vector <int> a , vector <int> b)
{
return a[1]<b[1] ;
}
int main()
{
vector<vector<int>> act ;
int n ,i ,j,m=0;
cout<<"Enter the no. of elements to be inserted\n" ;
cin>>n;
for(i=0 ;i<n ;i++)
{
vector<int> b(2);
cout<<"ENTER stating time and finishing time for activity "<<i+1<<endl;
cin>>b[0] ;
cin>>b[1] ;
act.push_back(b);
}
sort( act.begin(),act.end(),compare);
cout<<"ACTIVITY TABLE\n";
for(j=0 ;j<2 ;j++)
{
for(i=0 ;i<n ;i++)
{
cout<<act[i][j] << " ";
}
cout<<endl ;
}
vector<int> select;

select.push_back(m) ;
for(i=1 ;i<n ;i++){
if(act[i][0]>=act[m][1]){
m=i;
select.push_back(m) ;
}
}
cout<<"Selected activites are:\n";
for(int i=0;i<select.size();i++)
cout<<select[i] ;
}
119 changes: 119 additions & 0 deletions app_oran_count.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
#include <bits/stdc++.h>

using namespace std;

vector<string> split_string(string);

// Complete the countApplesAndOranges function below.
void countApplesAndOranges(int s, int t, int a, int b, vector<int> apples, vector<int> oranges)
{
int app_count=0,ora_count=0;
for(int i=0;i<apples.size();i++)
{
if(apples[i]>=0)
{
if(((s-a)<=apples[i]) && ((t-a)>=apples[i]))
app_count++;
}
}
for(int i=0;i<oranges.size();i++)
{
if(oranges[i]<=0)
{
if(((t-b)>=oranges[i])&&((s-b)<=oranges[i]))
{
ora_count++;
}
}
}
cout<<app_count<<"\n"<<ora_count;
}

int main()
{
string st_temp;
getline(cin, st_temp);

vector<string> st = split_string(st_temp);

int s = stoi(st[0]);

int t = stoi(st[1]);

string ab_temp;
getline(cin, ab_temp);

vector<string> ab = split_string(ab_temp);

int a = stoi(ab[0]);

int b = stoi(ab[1]);

string mn_temp;
getline(cin, mn_temp);

vector<string> mn = split_string(mn_temp);

int m = stoi(mn[0]);

int n = stoi(mn[1]);

string apples_temp_temp;
getline(cin, apples_temp_temp);

vector<string> apples_temp = split_string(apples_temp_temp);

vector<int> apples(m);

for (int i = 0; i < m; i++) {
int apples_item = stoi(apples_temp[i]);

apples[i] = apples_item;
}

string oranges_temp_temp;
getline(cin, oranges_temp_temp);

vector<string> oranges_temp = split_string(oranges_temp_temp);

vector<int> oranges(n);

for (int i = 0; i < n; i++) {
int oranges_item = stoi(oranges_temp[i]);

oranges[i] = oranges_item;
}

countApplesAndOranges(s, t, a, b, apples, oranges);

return 0;
}

vector<string> split_string(string input_string) {
string::iterator new_end = unique(input_string.begin(), input_string.end(), [] (const char &x, const char &y) {
return x == y and x == ' ';
});

input_string.erase(new_end, input_string.end());

while (input_string[input_string.length() - 1] == ' ') {
input_string.pop_back();
}

vector<string> splits;
char delimiter = ' ';

size_t i = 0;
size_t pos = input_string.find(delimiter);

while (pos != string::npos) {
splits.push_back(input_string.substr(i, pos - i));

i = pos + 1;
pos = input_string.find(delimiter, i);
}

splits.push_back(input_string.substr(i, min(pos, input_string.length()) - i + 1));

return splits;
}
17 changes: 17 additions & 0 deletions approx.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#include<iostream>
#include<cmath>
using namespace std;
int main()
{
float d,e,i,n,l=0,guess=0;
e=.01;
i=0.01;
cin>>n;

while(( (pow(guess,3))-n)>=e && guess<=n)
{
guess+=i;
l++;
}
cout<<guess;
}
24 changes: 24 additions & 0 deletions armstrong.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#include<iostream>
#include<cmath>
using namespace std;
int main()
{
int n,r,x,l=0;
cin>>n;
x=n;
while (x)
{
l++; //no. of digit
x = x/10;
}
int temp = n, sum = 0;
while (temp)
{
r = temp%10;
sum += pow(r, l);
temp = temp/10;
}
if(n==sum)
cout<<"Armstrong number";
else cout<<"Not Armstrong";
}
Loading

0 comments on commit 77e6b85

Please sign in to comment.