diff --git a/SPOJ_LIST/ABSP1.cpp b/SPOJ_LIST/ABSP1.cpp new file mode 100644 index 000000000..3239bfc4b --- /dev/null +++ b/SPOJ_LIST/ABSP1.cpp @@ -0,0 +1,37 @@ +#include + +#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>t; + while(t--) + { + ll n; + cin>>n; + ll a[n]; + fo(i,n) + cin>>a[i]; + ll sum=0; + for(ll i=0;i + +#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>t; + for(int i=0;i>n; + while(n%2==0) + { + n/=2; + } + cout<<"Case "<<(i+1)<<": "< + +#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>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) +**********************************************************/ \ No newline at end of file diff --git a/SPOJ_LIST/GIRLSNBS.cpp b/SPOJ_LIST/GIRLSNBS.cpp new file mode 100644 index 000000000..84e2b79df --- /dev/null +++ b/SPOJ_LIST/GIRLSNBS.cpp @@ -0,0 +1,47 @@ +#include + +#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>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< + +#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>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< + +#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>t; + for(int i=0;i>n; + + if(n<3) + ans=0; + else + ans=sqrt(1+n)-1; + cout<<"Case "<<(i+1)<<": "< + +#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>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< + +#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;i0) + { + 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< + +#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>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 + +#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>t; + while(t--) + { + ll n,m,maxa,maxb,ans; + cin>>n>>m; + vector a(n); + vector b(m); + + fo(i,n) + cin>>a[i]; + fo(i,m) + cin>>b[i]; + maxa=*max_element(a.begin(),a.end()); + maxb=*max_element(b.begin(),b.end()); + + // ans=max(maxa,maxb); + if(maxa>=maxb) + cout<<"Godzilla"<<"\n"; + else + cout<<"MechaGodzilla"<<"\n"; + + } + + + return 0; + } \ No newline at end of file diff --git a/SPOJ_LIST/codchess.cpp b/SPOJ_LIST/codchess.cpp new file mode 100644 index 000000000..66fac4f3e --- /dev/null +++ b/SPOJ_LIST/codchess.cpp @@ -0,0 +1,32 @@ +#include + +#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>t; + while(t--) + { + ll n;cin>>n; + + if(n%2) + cout<<0<<"\n"; + else + cout<<1<<"\n"; + + } + + + return 0; + } \ No newline at end of file diff --git a/SPOJ_LIST/crds.cpp b/SPOJ_LIST/crds.cpp new file mode 100644 index 000000000..fcd07b76d --- /dev/null +++ b/SPOJ_LIST/crds.cpp @@ -0,0 +1,35 @@ +#include + +#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>t; + while(t--) + { + ll n; + cin>>n; + + ll MOD=1000007; + + //ll ans=((((n%MOD)*(n%MOD)*(n%MOD))%MOD + ((n%MOD)*(n%MOD))%MOD -(2*(n%MOD))%MOD))/2%MOD; + ll ans=(((3*(n%MOD)*(n%MOD))+(n%MOD))/2)%MOD; + + cout< +#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 MOD 1000000007 +#define pb push_back +#define fo(i,n) for(ll i=0;i>t; + while(t--) + { + tem = 0;; + cin >> x; + if (x % 2 != 0) + { + cout << x << endl; + continue; + } + + while (x != 0) + { + tem = tem << 1; + tem = tem + (x & 1); + x = x >> 1; + + } + cout << tem << endl; + } + +return 0; +} \ No newline at end of file diff --git a/SPOJ_LIST/fashion.cpp b/SPOJ_LIST/fashion.cpp new file mode 100644 index 000000000..c44848499 --- /dev/null +++ b/SPOJ_LIST/fashion.cpp @@ -0,0 +1,44 @@ +#include + +#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>t; + while(t--) + { + ll n,hb=0,sum=0; + cin>>n; + ll a[n]; + ll b[n]; + fo(i,n) + cin>>a[i]; + fo(i,n) + cin>>b[i]; + + sort(a,a+n); + sort(b,b+n); + + fo(i,n) + { + hb=a[i]*b[i]; + sum+=hb; + } + cout< + +#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>t; + while(t--) + { + ll n,ans=0; + cin>>n; + for(ll i=5;n/i>=1;i*=5) + { + ans+=n/i; + } + cout< +#include +#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;i1; --i) + fact *= i; + return fact; +} + + +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; + cout< + +#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>t; + while(t--) + { + + } + + + return 0; + } + + + // TO DO \ No newline at end of file diff --git a/SPOJ_LIST/ieeeeebgam.cpp b/SPOJ_LIST/ieeeeebgam.cpp new file mode 100644 index 000000000..60a00a007 --- /dev/null +++ b/SPOJ_LIST/ieeeeebgam.cpp @@ -0,0 +1,33 @@ +#include + +#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>t; + while(t--) + { + int n; + cin>>n; + + double m=n; + double ans=m/(m+1); + cout< + +#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 st; + st.push('N'); + int l=s.length(); + string ns; + + for(int i=0;i='a' && s[i]<='z') || (s[i]>='A' && s[i]<='Z')) + ns+=s[i]; + else if(s[i]=='(') + st.push('('); + else if(s[i]==')') + { + while(st.top()!='N' && st.top()!='(') + { + char c=st.top(); + st.pop(); + ns+=c; + } + if(st.top()=='(') + { + char c=st.top(); + st.pop(); + } + } + else + { + while(st.top()!='N' && prec(s[i])<=prec(st.top())) + { + char c=st.top(); + st.pop(); + ns+=c; + } + st.push(s[i]); + } + } + //pop whatever remains + while(st.top()!='N') + { + char c=st.top(); + st.pop(); + ns+=c; + } + cout<>n; + while(n--) + { + string exp=""; + cin>>exp; + infix2postfix(exp); + } + return 0; + } \ No newline at end of file