Skip to content

Commit a95efe1

Browse files
authoredOct 5, 2020
Few important docs added along with curated SPOJ question list and solutions (sastava007#16)
Added list of famous SPOJ problems along with their solution and resources for getting started with CP.
1 parent 7ef4845 commit a95efe1

23 files changed

+922
-0
lines changed
 

‎SPOJ/SPOJ_LIST/ABSP1.cpp

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#include<bits/stdc++.h>
2+
3+
#define ll long long int
4+
#define watch(x) cout << (#x) << " is " << (x) << endl //watch function print variable and value for debugging
5+
#define count_ones __builtin_popcountll // count_ones(9) is equal to 2 valid for ll also
6+
#define fast_io ios_base::sync_with_stdio(false); cin.tie(NULL);
7+
#define fo(i,n) for(ll i=0;i<n;i++)
8+
using namespace std;
9+
10+
int main() {
11+
#ifndef ONLINE_JUDGE
12+
freopen("input.txt", "r", stdin);
13+
freopen("output.txt", "w", stdout);
14+
#endif
15+
fast_io
16+
17+
ll t;
18+
cin>>t;
19+
while(t--)
20+
{
21+
ll n;
22+
cin>>n;
23+
ll a[n];
24+
fo(i,n)
25+
cin>>a[i];
26+
ll sum=0;
27+
for(ll i=0;i<n;i++)
28+
{
29+
sum+=i*a[i]-(n-i-1)*a[i];
30+
}
31+
cout<<sum<<"\n";
32+
33+
}
34+
35+
36+
return 0;
37+
}

‎SPOJ/SPOJ_LIST/DOL.cpp

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#include<bits/stdc++.h>
2+
3+
#define ll long long int
4+
#define watch(x) cout << (#x) << " is " << (x) << endl //watch function print variable and value for debugging
5+
#define count_ones __builtin_popcountll // count_ones(9) is equal to 2 valid for ll also
6+
#define fast_io ios_base::sync_with_stdio(false); cin.tie(NULL);
7+
#define fo(i,n) for(ll i=0;i<n;i++)
8+
using namespace std;
9+
10+
int main() {
11+
#ifndef ONLINE_JUDGE
12+
freopen("input.txt", "r", stdin);
13+
freopen("output.txt", "w", stdout);
14+
#endif
15+
fast_io
16+
17+
ll t;
18+
cin>>t;
19+
for(int i=0;i<t;i++)
20+
{
21+
ll n;
22+
cin>>n;
23+
while(n%2==0)
24+
{
25+
n/=2;
26+
}
27+
cout<<"Case "<<(i+1)<<": "<<n<<"\n";
28+
}
29+
30+
31+
return 0;
32+
}

‎SPOJ/SPOJ_LIST/ESYRCRTN.cpp

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#include<bits/stdc++.h>
2+
3+
#define ll long long int
4+
#define watch(x) cout << (#x) << " is " << (x) << endl //watch function print variable and value for debugging
5+
#define count_ones __builtin_popcountll // count_ones(9) is equal to 2 valid for ll also
6+
#define fast_io ios_base::sync_with_stdio(false); cin.tie(NULL);
7+
#define fo(i,n) for(ll i=0;i<n;i++)
8+
using namespace std;
9+
10+
int main() {
11+
#ifndef ONLINE_JUDGE
12+
freopen("input.txt", "r", stdin);
13+
freopen("output.txt", "w", stdout);
14+
#endif
15+
fast_io
16+
17+
ll t;
18+
cin>>t;
19+
while(t--)
20+
{
21+
ll n;
22+
cin>>n;
23+
24+
ll a[]={1,4,6,5,2,0};
25+
cout<<(a[(n-1)%6])<<"\n";
26+
27+
}
28+
29+
30+
return 0;
31+
}
32+
/*******************************************************
33+
WRONG QUESTION(ERROR)
34+
**********************************************************/

‎SPOJ/SPOJ_LIST/GIRLSNBS.cpp

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
#include<bits/stdc++.h>
2+
3+
#define ll long long int
4+
#define watch(x) cout << (#x) << " is " << (x) << endl //watch function print variable and value for debugging
5+
#define count_ones __builtin_popcountll // count_ones(9) is equal to 2 valid for ll also
6+
#define fast_io ios_base::sync_with_stdio(false); cin.tie(NULL);
7+
#define fo(i,n) for(ll i=0;i<n;i++)
8+
using namespace std;
9+
10+
int main() {
11+
#ifndef ONLINE_JUDGE
12+
freopen("input.txt", "r", stdin);
13+
freopen("output.txt", "w", stdout);
14+
#endif
15+
fast_io
16+
17+
ll b,g;
18+
while(cin>>g>>b && g!=-1)
19+
{
20+
ll ans=0;
21+
ll k=g/(b+1);
22+
ll l=b/(g+1);
23+
if(g==b)
24+
{
25+
if(g==0 && b==0)
26+
ans=0;
27+
else
28+
ans=1;
29+
}
30+
else if(g>b)
31+
{
32+
if(g%(b+1)!=0)
33+
ans=1+k;
34+
else
35+
ans=k;
36+
}
37+
else
38+
{
39+
if(b%(g+1)!=0)
40+
ans=1+l;
41+
else
42+
ans=l;
43+
}
44+
cout<<ans<<"\n";
45+
}
46+
return 0;
47+
}

‎SPOJ/SPOJ_LIST/MOHIB.cpp

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#include<bits/stdc++.h>
2+
3+
#define ll long long int
4+
#define watch(x) cout << (#x) << " is " << (x) << endl //watch function print variable and value for debugging
5+
#define count_ones __builtin_popcountll // count_ones(9) is equal to 2 valid for ll also
6+
#define fast_io ios_base::sync_with_stdio(false); cin.tie(NULL);
7+
#define fo(i,n) for(ll i=0;i<n;i++)
8+
using namespace std;
9+
10+
int main() {
11+
#ifndef ONLINE_JUDGE
12+
freopen("input.txt", "r", stdin);
13+
freopen("output.txt", "w", stdout);
14+
#endif
15+
fast_io
16+
17+
ll t;
18+
cin>>t;
19+
while(t--)
20+
{
21+
ll x,a;
22+
cin>>x>>a;
23+
ll n=a-x;
24+
ll sum=n*(a+1);
25+
sum=sum-n*(n-1)/2;
26+
cout<<sum<<"\n";
27+
}
28+
29+
30+
return 0;
31+
}

‎SPOJ/SPOJ_LIST/PHT.cpp

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#include<bits/stdc++.h>
2+
3+
#define ll long long int
4+
#define watch(x) cout << (#x) << " is " << (x) << endl //watch function print variable and value for debugging
5+
#define count_ones __builtin_popcountll // count_ones(9) is equal to 2 valid for ll also
6+
#define fast_io ios_base::sync_with_stdio(false); cin.tie(NULL);
7+
#define fo(i,n) for(ll i=0;i<n;i++)
8+
using namespace std;
9+
10+
int main() {
11+
#ifndef ONLINE_JUDGE
12+
freopen("input.txt", "r", stdin);
13+
freopen("output.txt", "w", stdout);
14+
#endif
15+
fast_io
16+
17+
ll t;
18+
cin>>t;
19+
for(int i=0;i<t;i++)
20+
{
21+
ll n,ans=0;
22+
cin>>n;
23+
24+
if(n<3)
25+
ans=0;
26+
else
27+
ans=sqrt(1+n)-1;
28+
cout<<"Case "<<(i+1)<<": "<<ans<<"\n";
29+
30+
}
31+
32+
33+
return 0;
34+
}

‎SPOJ/SPOJ_LIST/QUADAREA.cpp

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#include<bits/stdc++.h>
2+
3+
#define ll long long int
4+
#define watch(x) cout << (#x) << " is " << (x) << endl //watch function print variable and value for debugging
5+
#define count_ones __builtin_popcountll // count_ones(9) is equal to 2 valid for ll also
6+
#define fast_io ios_base::sync_with_stdio(false); cin.tie(NULL);
7+
#define fo(i,n) for(ll i=0;i<n;i++)
8+
using namespace std;
9+
10+
int main() {
11+
#ifndef ONLINE_JUDGE
12+
freopen("input.txt", "r", stdin);
13+
freopen("output.txt", "w", stdout);
14+
#endif
15+
fast_io
16+
17+
ll t;
18+
cin>>t;
19+
while(t--)
20+
{
21+
double a,b,c,d;
22+
cin>>a>>b>>c>>d;
23+
24+
double sp=(a+b+c+d)/2;
25+
double area=sqrt((sp-a)*(sp-b)*(sp-c)*(sp-d));
26+
27+
cout<<fixed<<setprecision(2)<<(double)area<<"\n";
28+
29+
30+
}
31+
32+
33+
return 0;
34+
}

‎SPOJ/SPOJ_LIST/SPCQ.cpp

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#include<bits/stdc++.h>
2+
3+
#define ll long long int
4+
#define watch(x) cout << (#x) << " is " << (x) << endl //watch function print variable and value for debugging
5+
#define count_ones __builtin_popcountll // count_ones(9) is equal to 2 valid for ll also
6+
#define fast_io ios_base::sync_with_stdio(false); cin.tie(NULL);
7+
#define fo(i,n) for(ll i=0;i<n;i++)
8+
using namespace std;
9+
10+
11+
ll sum(ll n)
12+
{
13+
ll digsum=0;
14+
while(n>0)
15+
{
16+
digsum+=n%10;
17+
n/=10;
18+
}
19+
return digsum;
20+
}
21+
22+
int main() {
23+
#ifndef ONLINE_JUDGE
24+
freopen("input.txt", "r", stdin);
25+
freopen("output.txt", "w", stdout);
26+
#endif
27+
fast_io
28+
29+
ll t;
30+
cin>>t;
31+
while(t--)
32+
{
33+
ll n;
34+
cin>>n;
35+
while((n%sum(n))!=0)
36+
{
37+
n++;
38+
}
39+
cout<<n<<"\n";
40+
}
41+
return 0;
42+
}

‎SPOJ/SPOJ_LIST/SPOJQUESTIONSLIST.pdf

99.9 KB
Binary file not shown.

‎SPOJ/SPOJ_LIST/acpc11b.cpp

+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
#include<bits/stdc++.h>
2+
3+
#define ll long long int
4+
#define watch(x) cout << (#x) << " is " << (x) << endl //watch function print variable and value for debugging
5+
#define count_ones __builtin_popcountll // count_ones(9) is equal to 2 valid for ll also
6+
#define fast_io ios_base::sync_with_stdio(false); cin.tie(NULL);
7+
#define fo(i,n) for(ll i=0;i<n;i++)
8+
using namespace std;
9+
10+
int main() {
11+
#ifndef ONLINE_JUDGE
12+
freopen("input.txt", "r", stdin);
13+
freopen("output.txt", "w", stdout);
14+
#endif
15+
fast_io
16+
17+
ll t;
18+
cin>>t;
19+
while(t--)
20+
{
21+
ll n,m,diff=0,mini=INT_MAX;
22+
cin>>n;
23+
ll a[n];
24+
fo(i,n)
25+
cin>>a[i];
26+
cin>>m;
27+
ll b[m];
28+
fo(i,m)
29+
cin>>b[i];
30+
31+
sort(a,a+n);
32+
sort(b,b+m);
33+
34+
ll c=0,d=0;
35+
ll res=INT_MAX;
36+
37+
while(c<n && d<m)
38+
{
39+
if(abs(a[c]-b[d])<res)
40+
res=abs(a[c]-b[d]);
41+
42+
if(a[c]<b[d])
43+
c++;
44+
else
45+
d++;
46+
}
47+
cout<<res<<"\n";
48+
49+
}
50+
return 0;
51+
}

‎SPOJ/SPOJ_LIST/army.cpp

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
#include<bits/stdc++.h>
2+
3+
#define ll long long int
4+
#define watch(x) cout << (#x) << " is " << (x) << endl //watch function print variable and value for debugging
5+
#define count_ones __builtin_popcountll // count_ones(9) is equal to 2 valid for ll also
6+
#define fast_io ios_base::sync_with_stdio(false); cin.tie(NULL);
7+
#define fo(i,n) for(ll i=0;i<n;i++)
8+
using namespace std;
9+
10+
int main() {
11+
#ifndef ONLINE_JUDGE
12+
freopen("input.txt", "r", stdin);
13+
freopen("output.txt", "w", stdout);
14+
#endif
15+
fast_io
16+
17+
ll t;
18+
cin>>t;
19+
while(t--)
20+
{
21+
ll n,m,maxa,maxb,ans;
22+
cin>>n>>m;
23+
vector<ll> a(n);
24+
vector<ll> b(m);
25+
26+
fo(i,n)
27+
cin>>a[i];
28+
fo(i,m)
29+
cin>>b[i];
30+
maxa=*max_element(a.begin(),a.end());
31+
maxb=*max_element(b.begin(),b.end());
32+
33+
// ans=max(maxa,maxb);
34+
if(maxa>=maxb)
35+
cout<<"Godzilla"<<"\n";
36+
else
37+
cout<<"MechaGodzilla"<<"\n";
38+
39+
}
40+
41+
42+
return 0;
43+
}

‎SPOJ/SPOJ_LIST/codchess.cpp

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#include<bits/stdc++.h>
2+
3+
#define ll long long int
4+
#define watch(x) cout << (#x) << " is " << (x) << endl //watch function print variable and value for debugging
5+
#define count_ones __builtin_popcountll // count_ones(9) is equal to 2 valid for ll also
6+
#define fast_io ios_base::sync_with_stdio(false); cin.tie(NULL);
7+
#define fo(i,n) for(ll i=0;i<n;i++)
8+
using namespace std;
9+
10+
int main() {
11+
#ifndef ONLINE_JUDGE
12+
freopen("input.txt", "r", stdin);
13+
freopen("output.txt", "w", stdout);
14+
#endif
15+
fast_io
16+
17+
ll t;
18+
cin>>t;
19+
while(t--)
20+
{
21+
ll n;cin>>n;
22+
23+
if(n%2)
24+
cout<<0<<"\n";
25+
else
26+
cout<<1<<"\n";
27+
28+
}
29+
30+
31+
return 0;
32+
}

‎SPOJ/SPOJ_LIST/crds.cpp

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#include<bits/stdc++.h>
2+
3+
#define ll long long int
4+
#define watch(x) cout << (#x) << " is " << (x) << endl //watch function print variable and value for debugging
5+
#define count_ones __builtin_popcountll // count_ones(9) is equal to 2 valid for ll also
6+
#define fast_io ios_base::sync_with_stdio(false); cin.tie(NULL);
7+
#define fo(i,n) for(ll i=0;i<n;i++)
8+
using namespace std;
9+
10+
int main() {
11+
#ifndef ONLINE_JUDGE
12+
freopen("input.txt", "r", stdin);
13+
freopen("output.txt", "w", stdout);
14+
#endif
15+
fast_io
16+
17+
ll t;
18+
cin>>t;
19+
while(t--)
20+
{
21+
ll n;
22+
cin>>n;
23+
24+
ll MOD=1000007;
25+
26+
//ll ans=((((n%MOD)*(n%MOD)*(n%MOD))%MOD + ((n%MOD)*(n%MOD))%MOD -(2*(n%MOD))%MOD))/2%MOD;
27+
ll ans=(((3*(n%MOD)*(n%MOD))+(n%MOD))/2)%MOD;
28+
29+
cout<<ans<<"\n";
30+
31+
}
32+
33+
34+
return 0;
35+
}

‎SPOJ/SPOJ_LIST/ec_conb.cpp

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#include<bits/stdc++.h>
2+
#define ll long long int
3+
#define watch(x) cout << (#x) << " is " << (x) << endl //watch function print variable and value for debugging
4+
#define count_ones __builtin_popcountll // count_ones(9) is equal to 2 valid for ll also
5+
#define MOD 1000000007
6+
#define pb push_back
7+
#define fo(i,n) for(ll i=0;i<n;i++)
8+
using namespace std;
9+
10+
int main() {
11+
ios_base::sync_with_stdio(false);
12+
cin.tie(NULL);
13+
14+
int t, x,tem,tem2;
15+
cin>>t;
16+
while(t--)
17+
{
18+
tem = 0;;
19+
cin >> x;
20+
if (x % 2 != 0)
21+
{
22+
cout << x << endl;
23+
continue;
24+
}
25+
26+
while (x != 0)
27+
{
28+
tem = tem << 1;
29+
tem = tem + (x & 1);
30+
x = x >> 1;
31+
32+
}
33+
cout << tem << endl;
34+
}
35+
36+
return 0;
37+
}

‎SPOJ/SPOJ_LIST/fashion.cpp

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
#include<bits/stdc++.h>
2+
3+
#define ll long long int
4+
#define watch(x) cout << (#x) << " is " << (x) << endl //watch function print variable and value for debugging
5+
#define count_ones __builtin_popcountll // count_ones(9) is equal to 2 valid for ll also
6+
#define fast_io ios_base::sync_with_stdio(false); cin.tie(NULL);
7+
#define fo(i,n) for(ll i=0;i<n;i++)
8+
using namespace std;
9+
10+
int main() {
11+
#ifndef ONLINE_JUDGE
12+
freopen("input.txt", "r", stdin);
13+
freopen("output.txt", "w", stdout);
14+
#endif
15+
fast_io
16+
17+
ll t;
18+
cin>>t;
19+
while(t--)
20+
{
21+
ll n,hb=0,sum=0;
22+
cin>>n;
23+
ll a[n];
24+
ll b[n];
25+
fo(i,n)
26+
cin>>a[i];
27+
fo(i,n)
28+
cin>>b[i];
29+
30+
sort(a,a+n);
31+
sort(b,b+n);
32+
33+
fo(i,n)
34+
{
35+
hb=a[i]*b[i];
36+
sum+=hb;
37+
}
38+
cout<<sum<<"\n";
39+
40+
}
41+
42+
43+
return 0;
44+
}

‎SPOJ/SPOJ_LIST/fctrl.cpp

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#include<bits/stdc++.h>
2+
3+
#define ll long long int
4+
#define watch(x) cout << (#x) << " is " << (x) << endl //watch function print variable and value for debugging
5+
#define count_ones __builtin_popcountll // count_ones(9) is equal to 2 valid for ll also
6+
#define fast_io ios_base::sync_with_stdio(false); cin.tie(NULL);
7+
#define fo(i,n) for(ll i=0;i<n;i++)
8+
using namespace std;
9+
10+
int main() {
11+
#ifndef ONLINE_JUDGE
12+
freopen("input.txt", "r", stdin);
13+
freopen("output.txt", "w", stdout);
14+
#endif
15+
fast_io
16+
17+
ll t;
18+
cin>>t;
19+
while(t--)
20+
{
21+
ll n,ans=0;
22+
cin>>n;
23+
for(ll i=5;n/i>=1;i*=5)
24+
{
25+
ans+=n/i;
26+
}
27+
cout<<ans<<"\n";
28+
29+
30+
}
31+
32+
33+
return 0;
34+
}

‎SPOJ/SPOJ_LIST/fctrl2(c++17).cpp

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#include<bits/stdc++.h>
2+
#include <boost/multiprecision/cpp_int.hpp>
3+
#define ll long long int
4+
#define watch(x) cout << (#x) << " is " << (x) << endl //watch function print variable and value for debugging
5+
#define count_ones __builtin_popcountll // count_ones(9) is equal to 2 valid for ll also
6+
#define fast_io ios_base::sync_with_stdio(false); cin.tie(NULL);
7+
#define fo(i,n) for(ll i=0;i<n;i++)
8+
using boost::multiprecision::cpp_int;
9+
using namespace std;
10+
11+
12+
cpp_int boost_factorial(int num)
13+
{
14+
cpp_int fact = 1;
15+
for (int i=num; i>1; --i)
16+
fact *= i;
17+
return fact;
18+
}
19+
20+
21+
int main() {
22+
#ifndef ONLINE_JUDGE
23+
freopen("input.txt", "r", stdin);
24+
freopen("output.txt", "w", stdout);
25+
#endif
26+
fast_io
27+
28+
ll t;
29+
cin>>t;
30+
while(t--)
31+
{
32+
ll n;
33+
cin>>n;
34+
cout<<boost_factorial(n)<<"\n";
35+
36+
}
37+
38+
39+
return 0;
40+
}
+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#include<bits/stdc++.h>
2+
3+
#define ll long long int
4+
#define watch(x) cout << (#x) << " is " << (x) << endl //watch function print variable and value for debugging
5+
#define count_ones __builtin_popcountll // count_ones(9) is equal to 2 valid for ll also
6+
#define fast_io ios_base::sync_with_stdio(false); cin.tie(NULL);
7+
#define fo(i,n) for(ll i=0;i<n;i++)
8+
using namespace std;
9+
10+
int main() {
11+
#ifndef ONLINE_JUDGE
12+
freopen("input.txt", "r", stdin);
13+
freopen("output.txt", "w", stdout);
14+
#endif
15+
fast_io
16+
17+
ll t;
18+
cin>>t;
19+
while(t--)
20+
{
21+
22+
}
23+
24+
25+
return 0;
26+
}
27+
28+
29+
// TO DO

‎SPOJ/SPOJ_LIST/ieeeeebgam.cpp

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#include<bits/stdc++.h>
2+
3+
#define ll long long int
4+
#define watch(x) cout << (#x) << " is " << (x) << endl //watch function print variable and value for debugging
5+
#define count_ones __builtin_popcountll // count_ones(9) is equal to 2 valid for ll also
6+
#define fast_io ios_base::sync_with_stdio(false); cin.tie(NULL);
7+
#define fo(i,n) for(ll i=0;i<n;i++)
8+
using namespace std;
9+
10+
int main() {
11+
#ifndef ONLINE_JUDGE
12+
freopen("input.txt", "r", stdin);
13+
freopen("output.txt", "w", stdout);
14+
#endif
15+
fast_io
16+
17+
ll t;
18+
cin>>t;
19+
while(t--)
20+
{
21+
int n;
22+
cin>>n;
23+
24+
double m=n;
25+
double ans=m/(m+1);
26+
cout<<fixed<<setprecision(8)<<ans<<"\n";
27+
28+
29+
}
30+
31+
32+
return 0;
33+
}

‎SPOJ/SPOJ_LIST/infix2postfix.cpp

+85
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
#include<bits/stdc++.h>
2+
3+
#define ll long long int
4+
#define watch(x) cout << (#x) << " is " << (x) << endl //watch function print variable and value for debugging
5+
#define count_ones __builtin_popcountll // count_ones(9) is equal to 2 valid for ll also
6+
#define fast_io ios_base::sync_with_stdio(false); cin.tie(NULL);
7+
#define fo(i,n) for(ll i=0;i<n;i++)
8+
using namespace std;
9+
10+
int prec(char c)
11+
{
12+
if(c=='^')
13+
return 3;
14+
else if(c=='*' || c=='/')
15+
return 2;
16+
else if(c=='+' || c=='-')
17+
return 1;
18+
else
19+
return -1;
20+
}
21+
22+
void infix2postfix(string s)
23+
{
24+
stack<char> st;
25+
st.push('N');
26+
int l=s.length();
27+
string ns;
28+
29+
for(int i=0;i<l;i++)
30+
{
31+
if((s[i]>='a' && s[i]<='z') || (s[i]>='A' && s[i]<='Z'))
32+
ns+=s[i];
33+
else if(s[i]=='(')
34+
st.push('(');
35+
else if(s[i]==')')
36+
{
37+
while(st.top()!='N' && st.top()!='(')
38+
{
39+
char c=st.top();
40+
st.pop();
41+
ns+=c;
42+
}
43+
if(st.top()=='(')
44+
{
45+
char c=st.top();
46+
st.pop();
47+
}
48+
}
49+
else
50+
{
51+
while(st.top()!='N' && prec(s[i])<=prec(st.top()))
52+
{
53+
char c=st.top();
54+
st.pop();
55+
ns+=c;
56+
}
57+
st.push(s[i]);
58+
}
59+
}
60+
//pop whatever remains
61+
while(st.top()!='N')
62+
{
63+
char c=st.top();
64+
st.pop();
65+
ns+=c;
66+
}
67+
cout<<ns<<"\n";
68+
}
69+
70+
int main() {
71+
#ifndef ONLINE_JUDGE
72+
freopen("input.txt", "r", stdin);
73+
freopen("output.txt", "w", stdout);
74+
#endif
75+
fast_io
76+
77+
int n;cin>>n;
78+
while(n--)
79+
{
80+
string exp="";
81+
cin>>exp;
82+
infix2postfix(exp);
83+
}
84+
return 0;
85+
}
+168
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,168 @@
1+
C++
2+
->basic syntax
3+
->STL for cp
4+
5+
-> Pattern printing problems (improves thinking and loops)
6+
-> analysis and time complexity
7+
-> linear search basic traversal and circular array
8+
-> palindrome, armstrong, perfect,... numbers
9+
-> simple hashing problems
10+
-> prefix sum problems 1d 2d
11+
-> sliding window technique (problem)
12+
13+
-> binary search
14+
-> gcd of two numbers in log n (euclidean and extended euc...)
15+
-> linear diphantine equation
16+
-> checking prine in sqrt(n)
17+
-> sieve of eratosthenes
18+
-> segmented sieve
19+
-> finding prime factorition of number in log n
20+
-> euler totient functions
21+
-> fermat little theorem
22+
-> wilsons theorm
23+
24+
TOUGHER NUMBER THEORY
25+
-> find x^n in log n time
26+
-> modular airthmetic
27+
-> modular exponentiation
28+
-> chinese remainder theorm
29+
-> factorial modulo mod
30+
-> finding nCr and nPr for queries in constant time
31+
-> inclusion and exclusion principle
32+
33+
-> sorting algoritmms
34+
-> do problems which are constructive and have swapping terms in it
35+
-> solve problems related to two-pointer method
36+
-> bit manupulation(ls,rs,set,unset,msb,lsb)
37+
-> power set of array/string using bit
38+
-> number of sub-arrays with xor as zero (problem)
39+
-> greedy algorithms
40+
-> kadane's algorithm and problems related to that
41+
-> job sequencing and activity selection problems
42+
43+
end... number theory, bit manupulation, greedy algorithms
44+
45+
😵RECURSION
46+
-> basic recursion problems (finding factorial)
47+
-> implement binary search
48+
-> implement modular exponentiation
49+
-> finding subsets with given sum
50+
-> merge sort and quick sort
51+
-> solve problems related to merge sort(count inversion problem)
52+
-> backtracking problems sudoku and nqueen (dp path problems)
53+
54+
55+
-> meet in the middle algorithm and problems
56+
-> divide and conquer (practice from codeforces only)
57+
-> next-greater/next-smaller element using stack
58+
-> problems related to paranthesis
59+
-> largest rectangular ares in histogram
60+
(concept is used in lot of problems)
61+
-> problems related to heap (priority queue)(greedy, stl)
62+
63+
64+
65+
☣️🦠☠️ HARDER TOPICS (dont give up!)
66+
67+
68+
STRINGS:
69+
-> learn about hashing on strings and solve problems, understand when collison happens.
70+
-> rabin karp algorithm
71+
-> prefix function
72+
-> kmp algorithm
73+
-> z-function
74+
-> manachers' algorithm
75+
-> solve various problems from different platforms
76+
77+
78+
TREES
79+
-> tree/graph representation
80+
-> DFS/BFS traversal int graph/tree
81+
-> diameter/height/level/etc of a tree
82+
-> euler tour of tree
83+
-> finding LCA using euler tour
84+
-> finding LCA using binary lifting (log n time per query)
85+
-> distance between two nodes
86+
-> subtree problems
87+
-> solve problems (spoj recommended)
88+
89+
90+
GRAPHS
91+
-> connected components
92+
-> topological sort
93+
-> cycle detection in graph
94+
-> bipartite check in graph
95+
-> shortest connected component (SCC) using Kosaraju's algorithm
96+
-> Dijkstra's algorithm (shortest path)
97+
-> bellman ford algorithm (shortest path when there are negative weights)
98+
-> floyd warshl algorithm
99+
-> solve problems (hackerearth, cp-algorithms)
100+
101+
-> bridges in a graph
102+
-> articulation point in a graph
103+
-> minimum spanning tree using Kruskal's algorithm
104+
-> Prim's algorithm
105+
-> 0/1 BFS (dijkstra takes nlog n time might give TLE. but this works in linear time)
106+
-> finding bridges online
107+
-> solve problems
108+
109+
110+
🤯 DYNAMIC PROGRAMMING
111+
112+
!!!avoid iterative DP if you are a beginner in DP
113+
instead start with recursion and try to memoise the solution.
114+
115+
-> need to be expert in recursion
116+
-> understand memoisation
117+
-> initially solve all the common existing DP problems (LCS, knapsac, etc)
118+
-> solve atcoder educational contest on DP (all 26 questions!)
119+
-> solve problems from various platforms
120+
-> understand how do we write recurrence for digit DP (cf-blog) and solve problems on it.
121+
-> DP with bitmask and solve problems
122+
-> DP on trees
123+
-> SOS DP (cf- blog)
124+
125+
126+
-> disjoint set(using all optimisatios)
127+
-> offline queries using disjoint set (problem: colourful array on SPOJ)(for understanding above topic)
128+
-> Kruskal's algo using disjoint set and solve bunch of problens
129+
130+
131+
-> sparse table (not much important. segment trees do the job)
132+
-> fenwick tree and binary lifting on fenwick tree
133+
(read about range update trick also)
134+
-> questions on fenwick tree
135+
136+
137+
138+
-> Matrix exponentiation(problems)
139+
-> Sqrt decomposition technique(preferred over segment tree)
140+
-> update and query operations
141+
-> Mo's algorithm (powerful array from codeforces)
142+
-> Mo's algo on trees (long challenges mostly)
143+
-> Segment trees (most importent data structure) (Range queries and point updates)
144+
-> Lazy propagation on Segment trees (range updates)
145+
146+
147+
-> Spraue grundy theorm (SEEN VERY RARE)
148+
-> Flows and related problems (max flow, min flow) (cp-algorithm)
149+
-> heavy-light decomposition on trees
150+
-> Convex hull algorithm
151+
-> FFT/NTT (any maths blog)
152+
153+
154+
155+
156+
157+
158+
159+
160+
161+
162+
163+
164+
165+
166+
167+
168+

‎library/Cpp_STL_ReferenceManual.pdf

512 KB
Binary file not shown.

‎library/all stl functions.pdf

512 KB
Binary file not shown.

0 commit comments

Comments
 (0)
Please sign in to comment.