forked from shivaylamba/Hacktoberfest
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request shivaylamba#645 from thedrivingforc/master
a list of handpicked sopj questions and codes to few of adhoc ones
- Loading branch information
Showing
20 changed files
with
754 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
#include<bits/stdc++.h> | ||
|
||
#define ll long long int | ||
#define watch(x) cout << (#x) << " is " << (x) << endl //watch function print variable and value for debugging | ||
#define count_ones __builtin_popcountll // count_ones(9) is equal to 2 valid for ll also | ||
#define fast_io ios_base::sync_with_stdio(false); cin.tie(NULL); | ||
#define fo(i,n) for(ll i=0;i<n;i++) | ||
using namespace std; | ||
|
||
int main() { | ||
#ifndef ONLINE_JUDGE | ||
freopen("input.txt", "r", stdin); | ||
freopen("output.txt", "w", stdout); | ||
#endif | ||
fast_io | ||
|
||
ll t; | ||
cin>>t; | ||
while(t--) | ||
{ | ||
ll n; | ||
cin>>n; | ||
ll a[n]; | ||
fo(i,n) | ||
cin>>a[i]; | ||
ll sum=0; | ||
for(ll i=0;i<n;i++) | ||
{ | ||
sum+=i*a[i]-(n-i-1)*a[i]; | ||
} | ||
cout<<sum<<"\n"; | ||
|
||
} | ||
|
||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
#include<bits/stdc++.h> | ||
|
||
#define ll long long int | ||
#define watch(x) cout << (#x) << " is " << (x) << endl //watch function print variable and value for debugging | ||
#define count_ones __builtin_popcountll // count_ones(9) is equal to 2 valid for ll also | ||
#define fast_io ios_base::sync_with_stdio(false); cin.tie(NULL); | ||
#define fo(i,n) for(ll i=0;i<n;i++) | ||
using namespace std; | ||
|
||
int main() { | ||
#ifndef ONLINE_JUDGE | ||
freopen("input.txt", "r", stdin); | ||
freopen("output.txt", "w", stdout); | ||
#endif | ||
fast_io | ||
|
||
ll t; | ||
cin>>t; | ||
for(int i=0;i<t;i++) | ||
{ | ||
ll n; | ||
cin>>n; | ||
while(n%2==0) | ||
{ | ||
n/=2; | ||
} | ||
cout<<"Case "<<(i+1)<<": "<<n<<"\n"; | ||
} | ||
|
||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
#include<bits/stdc++.h> | ||
|
||
#define ll long long int | ||
#define watch(x) cout << (#x) << " is " << (x) << endl //watch function print variable and value for debugging | ||
#define count_ones __builtin_popcountll // count_ones(9) is equal to 2 valid for ll also | ||
#define fast_io ios_base::sync_with_stdio(false); cin.tie(NULL); | ||
#define fo(i,n) for(ll i=0;i<n;i++) | ||
using namespace std; | ||
|
||
int main() { | ||
#ifndef ONLINE_JUDGE | ||
freopen("input.txt", "r", stdin); | ||
freopen("output.txt", "w", stdout); | ||
#endif | ||
fast_io | ||
|
||
ll t; | ||
cin>>t; | ||
while(t--) | ||
{ | ||
ll n; | ||
cin>>n; | ||
|
||
ll a[]={1,4,6,5,2,0}; | ||
cout<<(a[(n-1)%6])<<"\n"; | ||
|
||
} | ||
|
||
|
||
return 0; | ||
} | ||
/******************************************************* | ||
WRONG QUESTION(ERROR) | ||
**********************************************************/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
#include<bits/stdc++.h> | ||
|
||
#define ll long long int | ||
#define watch(x) cout << (#x) << " is " << (x) << endl //watch function print variable and value for debugging | ||
#define count_ones __builtin_popcountll // count_ones(9) is equal to 2 valid for ll also | ||
#define fast_io ios_base::sync_with_stdio(false); cin.tie(NULL); | ||
#define fo(i,n) for(ll i=0;i<n;i++) | ||
using namespace std; | ||
|
||
int main() { | ||
#ifndef ONLINE_JUDGE | ||
freopen("input.txt", "r", stdin); | ||
freopen("output.txt", "w", stdout); | ||
#endif | ||
fast_io | ||
|
||
ll b,g; | ||
while(cin>>g>>b && g!=-1) | ||
{ | ||
ll ans=0; | ||
ll k=g/(b+1); | ||
ll l=b/(g+1); | ||
if(g==b) | ||
{ | ||
if(g==0 && b==0) | ||
ans=0; | ||
else | ||
ans=1; | ||
} | ||
else if(g>b) | ||
{ | ||
if(g%(b+1)!=0) | ||
ans=1+k; | ||
else | ||
ans=k; | ||
} | ||
else | ||
{ | ||
if(b%(g+1)!=0) | ||
ans=1+l; | ||
else | ||
ans=l; | ||
} | ||
cout<<ans<<"\n"; | ||
} | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
#include<bits/stdc++.h> | ||
|
||
#define ll long long int | ||
#define watch(x) cout << (#x) << " is " << (x) << endl //watch function print variable and value for debugging | ||
#define count_ones __builtin_popcountll // count_ones(9) is equal to 2 valid for ll also | ||
#define fast_io ios_base::sync_with_stdio(false); cin.tie(NULL); | ||
#define fo(i,n) for(ll i=0;i<n;i++) | ||
using namespace std; | ||
|
||
int main() { | ||
#ifndef ONLINE_JUDGE | ||
freopen("input.txt", "r", stdin); | ||
freopen("output.txt", "w", stdout); | ||
#endif | ||
fast_io | ||
|
||
ll t; | ||
cin>>t; | ||
while(t--) | ||
{ | ||
ll x,a; | ||
cin>>x>>a; | ||
ll n=a-x; | ||
ll sum=n*(a+1); | ||
sum=sum-n*(n-1)/2; | ||
cout<<sum<<"\n"; | ||
} | ||
|
||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
#include<bits/stdc++.h> | ||
|
||
#define ll long long int | ||
#define watch(x) cout << (#x) << " is " << (x) << endl //watch function print variable and value for debugging | ||
#define count_ones __builtin_popcountll // count_ones(9) is equal to 2 valid for ll also | ||
#define fast_io ios_base::sync_with_stdio(false); cin.tie(NULL); | ||
#define fo(i,n) for(ll i=0;i<n;i++) | ||
using namespace std; | ||
|
||
int main() { | ||
#ifndef ONLINE_JUDGE | ||
freopen("input.txt", "r", stdin); | ||
freopen("output.txt", "w", stdout); | ||
#endif | ||
fast_io | ||
|
||
ll t; | ||
cin>>t; | ||
for(int i=0;i<t;i++) | ||
{ | ||
ll n,ans=0; | ||
cin>>n; | ||
|
||
if(n<3) | ||
ans=0; | ||
else | ||
ans=sqrt(1+n)-1; | ||
cout<<"Case "<<(i+1)<<": "<<ans<<"\n"; | ||
|
||
} | ||
|
||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
#include<bits/stdc++.h> | ||
|
||
#define ll long long int | ||
#define watch(x) cout << (#x) << " is " << (x) << endl //watch function print variable and value for debugging | ||
#define count_ones __builtin_popcountll // count_ones(9) is equal to 2 valid for ll also | ||
#define fast_io ios_base::sync_with_stdio(false); cin.tie(NULL); | ||
#define fo(i,n) for(ll i=0;i<n;i++) | ||
using namespace std; | ||
|
||
int main() { | ||
#ifndef ONLINE_JUDGE | ||
freopen("input.txt", "r", stdin); | ||
freopen("output.txt", "w", stdout); | ||
#endif | ||
fast_io | ||
|
||
ll t; | ||
cin>>t; | ||
while(t--) | ||
{ | ||
double a,b,c,d; | ||
cin>>a>>b>>c>>d; | ||
|
||
double sp=(a+b+c+d)/2; | ||
double area=sqrt((sp-a)*(sp-b)*(sp-c)*(sp-d)); | ||
|
||
cout<<fixed<<setprecision(2)<<(double)area<<"\n"; | ||
|
||
|
||
} | ||
|
||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
#include<bits/stdc++.h> | ||
|
||
#define ll long long int | ||
#define watch(x) cout << (#x) << " is " << (x) << endl //watch function print variable and value for debugging | ||
#define count_ones __builtin_popcountll // count_ones(9) is equal to 2 valid for ll also | ||
#define fast_io ios_base::sync_with_stdio(false); cin.tie(NULL); | ||
#define fo(i,n) for(ll i=0;i<n;i++) | ||
using namespace std; | ||
|
||
|
||
ll sum(ll n) | ||
{ | ||
ll digsum=0; | ||
while(n>0) | ||
{ | ||
digsum+=n%10; | ||
n/=10; | ||
} | ||
return digsum; | ||
} | ||
|
||
int main() { | ||
#ifndef ONLINE_JUDGE | ||
freopen("input.txt", "r", stdin); | ||
freopen("output.txt", "w", stdout); | ||
#endif | ||
fast_io | ||
|
||
ll t; | ||
cin>>t; | ||
while(t--) | ||
{ | ||
ll n; | ||
cin>>n; | ||
while((n%sum(n))!=0) | ||
{ | ||
n++; | ||
} | ||
cout<<n<<"\n"; | ||
} | ||
return 0; | ||
} |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
#include<bits/stdc++.h> | ||
|
||
#define ll long long int | ||
#define watch(x) cout << (#x) << " is " << (x) << endl //watch function print variable and value for debugging | ||
#define count_ones __builtin_popcountll // count_ones(9) is equal to 2 valid for ll also | ||
#define fast_io ios_base::sync_with_stdio(false); cin.tie(NULL); | ||
#define fo(i,n) for(ll i=0;i<n;i++) | ||
using namespace std; | ||
|
||
int main() { | ||
#ifndef ONLINE_JUDGE | ||
freopen("input.txt", "r", stdin); | ||
freopen("output.txt", "w", stdout); | ||
#endif | ||
fast_io | ||
|
||
ll t; | ||
cin>>t; | ||
while(t--) | ||
{ | ||
ll n,m,diff=0,mini=INT_MAX; | ||
cin>>n; | ||
ll a[n]; | ||
fo(i,n) | ||
cin>>a[i]; | ||
cin>>m; | ||
ll b[m]; | ||
fo(i,m) | ||
cin>>b[i]; | ||
|
||
sort(a,a+n); | ||
sort(b,b+m); | ||
|
||
ll c=0,d=0; | ||
ll res=INT_MAX; | ||
|
||
while(c<n && d<m) | ||
{ | ||
if(abs(a[c]-b[d])<res) | ||
res=abs(a[c]-b[d]); | ||
|
||
if(a[c]<b[d]) | ||
c++; | ||
else | ||
d++; | ||
} | ||
cout<<res<<"\n"; | ||
|
||
} | ||
return 0; | ||
} |
Oops, something went wrong.