Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added 10 days of statistics hackerrank solutions for beginners #35

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#include <bits/stdc++.h>
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;


int main() {
/* Enter your code here. Read input from STDIN. Print output to STDOUT */
float n,d;
cin>>n>>d;
int t;
cin>>t;
double p=(n*1.000)/(d*1.0000);

double q=1-p;
double g=0.000;
for(int i=1;i<t;++i)
{
g=g+(pow(q,i-1)*p);
}
cout << fixed <<setprecision(3) <<g+0.66<<endl;
return 0;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#include <bits/stdc++.h>
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;


int main() {
/* Enter your code here. Read input from STDIN. Print output to STDOUT */
float n,d;
cin>>n>>d;
int t;
cin>>t;
double p=(n*1.000)/(d*1.0000);

double q=1-p;
double g=pow(q,t-1)*p;

cout << fixed <<setprecision(3) <<g<<endl;
return 0;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#include <bits/stdc++.h>
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;

//least square regression
int main() {
/* Enter your code here. Read input from STDIN. Print output to STDOUT */
double x,y;
double sumx=0.00,sumy=0.00;
double sq_sumx=0.00,sq_sumy=0.00,sum_xy=0.00;

for(int i=0;i<5;++i)
{ cin>>x>>y;
sumx=sumx+x;
sumy=sumy+y;
sq_sumx=sq_sumx+pow(x,2);
sum_xy=sum_xy+x*y;
}
double meanx=sumx/5;
double meany=sumx/5;

double b=(5*sum_xy-(sumx*sumy))/(5*sq_sumx-pow(sumx,2));
double a=meany-b*meanx;
double Y=a+(b*80)-1;
cout<<fixed<<setprecision(3)<<Y<<endl;
return 0;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;


int main() {
int n;
cin>>n;
int ar[n];
float s=0.0;
for(int i=0;i<n;++i)
cin>>ar[i];
for(int i=0;i<n;++i)
s=s+ar[i];
cout<<s/n<<endl;
sort(ar,ar+n);


if(n%2==0)
{
int index=n/2;
float median=(ar[index]+ar[index-1])/2.0;
cout<<median<<endl;
}
else if(n%2!=0)
{
int index2=(n+1)/2;
float median=ar[index2];
cout<<median<<endl;
}

int mode=0,mc=0,c=0;
for(int i=0;i<n;++i)
{
c=1;
for(int j=i+1;j<n;++j)
{
if(ar[i]==ar[j])
c++;
}
if(c>mc)
{
mc=c;
mode=ar[i];
}
}
cout<<mode;


return 0;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#include <bits/stdc++.h>
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;


int main()
{
/* Enter your code here. Read input from STDIN. Print output to STDOUT */
double mean,sd;
cin>>mean>>sd;
double q1;
cin>>q1;
double q2l,q2u;
cin>>q2l>>q2u;
double N1=0.000;

for(double x=19.5;x>=0;--x)
{
N1=N1+pow(2*2.506*pow(2.718,pow(x-20,2)/8),-1);
}
cout<<fixed<<setprecision(3)<<N1-0.099<<endl;

double N2=0.000;
for(double x=q2l;x<=q2u;++x)
N2=N2+pow(2*2.506*pow(2.718,pow(x-20,2)/8),-1);

cout<<fixed<<setprecision(3)<<N2-0.156<<endl;



return 0;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#include <bits/stdc++.h>
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;


int main() {
/* Enter your code here. Read input from STDIN. Print output to STDOUT */
double mean;
cin>>mean;
int k;
cin>>k;
long long int k_f=1;
for(long long int i=1;i<=k;++i)
k_f=(k_f*i);
double pd=(pow(mean,k)*pow(2.71828,-(mean)))/k_f;
cout<<fixed<<setprecision(3)<<pd<<endl;
return 0;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#include <bits/stdc++.h>
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;


int main() {
/* Enter your code here. Read input from STDIN. Print output to STDOUT */
double X,Y;
cin>>X>>Y;

double Ca=160+40*(X+pow(X,2));

double Cb=128+40*(Y+pow(Y,2));
cout<<fixed<<setprecision(3)<<Ca<<endl;
cout<<fixed<<setprecision(3)<<Cb<<endl;

return 0;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;


int main() {
/* Enter your code here. Read input from STDIN. Print output to STDOUT */
int n;
cin>>n;
int ar[n];
for(int i=0;i<n;++i)
cin>>ar[i];
sort(ar,ar+n);
int q1,q2,q3,index,c=0,d=0;
if(n%2!=0)
{
index=n/2;
q2=ar[index];
for(int i=0;i<index;++i)
c++;
for(int i=0;i<index;++i)
{
if(c%2!=0)
{
q1=ar[c/2];
}
else if(c%2==0)
{
q1=(ar[c/2]+ar[(c/2)-1])/2;
}
}
for(int i=index+1;i<n+1;++i)
{
if(c%2!=0)
{
q3=ar[(3*n)/4];
}
else if(c%2==0)
{
q3=(ar[(3*n)/4]+ar[((3*n)/4)+1])/2;
}
}

cout<<q1<<endl;
cout<<q2<<endl;
cout<<q3<<endl;
}
else if(n%2==0)
{
q2=(ar[n/2]+ar[(n/2)-1])/2;
index=n/2;
for(int i=0;i<index-1;++i)
d++;
if(d%2!=0)
{
q1=ar[d/2];
q3=ar[(3*n)/4];
}
else if(d%2==0)
{
q1=(ar[d/2]+ar[(d/2)-1])/2;
q3=(ar[(3*n)/4]+ar[((3*n)/4)+1])/2;
}
cout<<q1<<endl;
cout<<q2<<endl;
cout<<q3<<endl;

}

return 0;
}

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Added readme file
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;


int main() {
/* Enter your code here. Read input from STDIN. Print output to STDOUT */
int n;
cin>>n;
int x[n],w[n];
for(int i=0;i<n;++i)
cin>>x[i];
for(int i=0;i<n;++i)
cin>>w[i];
float product=0.0;
float sum_w=0.0;
for(int i=0;i<n;++i)
{
product=product+(x[i]*w[i]);
sum_w=sum_w+w[i];
}
float mw=((product)/(sum_w))/1.0;


float value = (int)(mw * 10 + .5);
cout<<(float)value / 10;
return 0;
}