- #include<bits/stdc++.h>
- using namespace std;
- int stck[100000];
- int tp=-1,num,mx=5;
- void pop()
- {
- if(tp<0)
- cout<<"\n\t\t"<<"Stack is empty"<<endl<<endl;
- else
- {
- cout<<"\n\t\t"<<"Pop Item is "<<stck[tp]<<endl<<endl;
- tp--;
- }
- }
- void push()
- {
- if(tp==mx-1)
- cout<<"\n\t\t"<<"Stack is full"<<endl<<endl;
- else
- {
- int ss;
- cout<<"what number you push ? ";
- cin>>ss;
- stck[++tp]= ss;
- }
- }
- void display()
- {
- if(tp<0)
- cout<<"\n\t\t"<<"Stack is empty"<<endl<<endl;
- else
- {
- cout<<"\n\t\t"<<"Numbers of stack is: ";
- for(int i=0; i<=tp; i++)
- cout<<stck[i]<<" ";
- cout<<endl<<endl;
- }
- }
- void top()
- {
- if(tp<0)
- cout<<"\n\t\t"<<"Stack is empty"<<endl<<endl;
- else
- {
- cout<<"\n\t\t"<<"Top Item is "<<stck[tp]<<endl<<endl;
- }
- }
- int st()
- {
- cout<<"\t"<<"1.PUSH"<<endl<<endl;
- cout<<"\t"<<"2.POP"<<endl<<endl;
- cout<<"\t"<<"3.DISPLAY"<<endl<<endl;
- cout<<"\t"<<"4.TOP"<<endl<<endl;
- cout<<"\t"<<"5.EXIT"<<endl<<endl;
- int s;
- cout<<endl<<endl<<"Plz Choice your Option :";
- cin>>s;
- switch(s)
- {
- case 1:
- push();
- break;
- case 2:
- pop();
- break;
- case 3:
- display();
- break;
- case 4:
- top();
- break;
- case 5:
- exit(0);
- break;
- default:
- cout<<"\n\t\t"<<"You enter wrong number"<<endl;
- }
- }
- int main()
- {
- while(st()!=5)
- {
- st();
- }
- return 0;
- }
Thursday, 26 September 2019
Stack in cpp
Wednesday, 18 September 2019
Sum of divisor of large number
- #include<bits/stdc++.h>
- #include<set>
- #include<iterator>
- #include<map>
- #include<math.h>
- using namespace std;
- int main()
- {
- unsigned long long int num,sum,ii,n;
- map<long long int,long long int> mp;
- set<long long int>st;
- set<long long int>:: iterator it;
- int t;
- cin>>t;
- while(t--)
- {
- cin>>num;
- n=num;
- if(num==1)
- cout<<"1"<<endl;
- if(num==1)
- continue;
- long long int i=2;
- while(n>1)
- {
- if(n%i==0)
- {
- mp[i]++;
- st.insert(i);
- n/=i;
- }
- else
- i++;
- }
- unsigned long long int sum=1,ans=1;
- for(it=st.begin(); it!=st.end(); it++)
- {
- ii=*it;
- // cout<<mp[ii]<<"\t"<<ii<<endl;
- for(int i=1; i<=mp[ii]+1; i++)
- ans*= ii;
- sum= sum * ((ans-1)/(ii-1));
- ans=1;
- }
- cout<<sum-num<<endl;
- st.clear();
- mp.clear();
- }
- return 0;
- }
Subscribe to:
Comments (Atom)
variable declaration of c program
#include <stdbool.h> #include<bits/stdc++.h> #include <stdio.h> #include <string.h> #include <std...
-
#include<bits/stdc++.h> #include<cmath> #include<algorithm> #define mx 20000005 using namespace std ; ...
-
#include<stdio.h> #include<string.h> int main ( void ) { char y [ 100001 ] ; int m4,m100,m400,m15...
-
#include<bits/stdc++.h> using namespace std ; int main ( ) { int arr [ 10005 ] ; int n,m,mi,d ; ...